tauri_sys::event

Function listen

source
pub async fn listen<T>(
    event: &str,
) -> Result<impl Stream<Item = Event<T>>, Error>
where T: DeserializeOwned + 'static,
Expand description

Listen to an 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::listen;
use web_sys::console;

let events = listen::<String>("error");

while let Some(event) = events.next().await {
    console::log_1(&format!("Got error in window {}, payload: {}", event.window_label, event.payload).into());
}