Skip to main content

run_async

Function run_async 

Source
pub fn run_async<M: Send + 'static>(
    f: impl FnMut(&mut Context, &mut Vec<M>) + Send + 'static,
) -> Result<AsyncRunHandle<M>>
Available on crate features async and crossterm only.
Expand description

Run the TUI loop asynchronously with default configuration.

Requires the async feature. Spawns the render loop in a blocking thread and returns an owned AsyncRunHandle. The handle sends messages directly, can be cloned into an AsyncSender, supports cooperative cancellation, and exposes render-loop I/O or panic failures when joined.

Returns io::ErrorKind::NotConnected when stdin or stdout is not a terminal. Use frame with a custom backend for headless rendering.

ยงExample

let run = slt::run_async::<String>(|ui, messages| {
    for msg in messages.drain(..) {
        ui.text(msg);
    }
})?;
run.send("hello from async".to_string()).await.ok();
run.cancel_and_join().await.map_err(std::io::Error::other)?;