tokio-immediate 0.2.0

Asynchronous glue for your immediate mode UI
Documentation

tokio-immediate

docs.rs tokio-immediate docs.rs tokio-immediate-egui

Primitives for calling asynchronous code from immediate mode UIs.

tokio-immediate manages asynchronous tasks for you and wakes up the main UI loop when task completes or sends status updates via a channel.

Examples

The repository includes runnable examples for several immediate UI frameworks:

Example Framework
example-egui egui + eframe
example-egui-minimal egui + eframe
example-imgui-minimal Dear ImGui (dear-imgui-rs + dear-app)
example-ratatui-minimal ratatui + crossterm

The full egui example demonstrates multi-viewport support, sync::watch channels for streaming progress updates, and cancellation tokens.

example-egui demo

Crates

Crate Docs Description
tokio-immediate docs.rs/tokio-immediate Core library, framework-agnostic
tokio-immediate-egui docs.rs/tokio-immediate-egui Optional egui integration via an egui::Plugin

Simplified code (with egui-specific helper plugin)

use tokio_immediate_egui::single::{AsyncCall, AsyncCallState};
use tokio_immediate_egui::EguiAsync;

// During app setup - create an EguiAsync and register its plugin:
let egui_async = EguiAsync::default();
cc.egui_ctx.add_plugin(egui_async.plugin());
let mut task: AsyncCall<String> = egui_async.new_call();

// In your update() loop:
task.poll(); // check for completion — call once per frame

match &*task {
    AsyncCallState::Stopped => { /* never started or aborted */ }
    AsyncCallState::Running(handle) => {
        ui.spinner();
        if ui.button("Abort").clicked() {
            handle.abort();
        }
    }
    AsyncCallState::Completed(value) => {
        ui.label(value);
    }
}

// To kick off work:
task.start(async {
    tokio::time::sleep(std::time::Duration::from_secs(2)).await;
    String::from("done!")
});

When the spawned future finishes, the library automatically requests a repaint of the viewport that owns the AsyncCall, so you never miss the result.

Development

A justfile provides common development recipes (need just to run):

just clippy   # lint with Clippy (all crates, all feature combinations)
just test     # run tests
just doc      # generate documentation
just build    # build all examples (debug)
just fmt      # format code