Skip to main content

Module async_completion

Module async_completion 

Source
Expand description

Generic, runtime-agnostic delivery of a one-shot main-thread callback that runs with a fresh EventContext bound to a window’s tree.

This is the plumbing the optional teksilo-async crate uses to implement spawn_local_with: a future runs on the main-thread executor, and when it completes its result is handed to a callback that needs ambient context operations (open_window, send_intent, …). Those operations require an EventContext, which only exists during event dispatch — so the callback is registered here (keyed by an id and the originating window) and delivered later by teksilo-app, which routes an AsyncCompletionPayload to the window’s tree and calls AsyncCompletionHandle::deliver inside a freshly-minted context.

It mirrors the file-dialog result-delivery pattern, but uses only teksilo-core types so a crate layered above teksilo-app (like teksilo-async) can register callbacks without forcing teksilo-app to depend on it (which would be a dependency cycle). There is no async, future, or runtime type here — just a callback registry and a Send payload.

Structs§

AsyncCompletionHandle
Main-thread registry of pending async completions. Clone shares the same inner state (Rc), so the executor and the app event loop both hold a handle to one registry. !Send by construction — completions only ever run on the UI thread.
AsyncCompletionPayload
Send payload posted through AppEventPoster when an async task completes. teksilo-app downcasts it, routes to the target window’s tree, and calls AsyncCompletionHandle::deliver with a fresh context. Carries only ids — the (!Send) callback stays in the registry.