tauri_sys::event

Function once

source
pub async fn once<T>(event: &str) -> Result<Event<T>, Error>
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. See Differences to the JavaScript API for details.

§Example

use tauri_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());