Function tauri_wasm::api::event::once

source ·
pub async fn once<T>(event: &str) -> Result<Event<T>>
where T: DeserializeOwned + 'static,
Expand description

Listen to an one-off event from the backend.

The returned Future will automatically clean up it’s underlying event listener when dropped, so no manual unlisten function needs to be called.

§Example

use tauri_wasm::api::event::once;
use serde::Deserialize;
use web_sys::console;

#[derive(Deserialize)]
interface LoadedPayload {
  logged_in: bool,
  token: String
}
 
const event = once::<LoadedPayload>("loaded").await?;
 
console::log_1!(&format!("App is loaded, loggedIn: {}, token: {}", event.payload.logged_in, event.payload.token).into());