Expand description
Single-threaded polling-based executor suitable for use in games, embedded systems or WASM.
This crate provides an executor to run async functions in single-threaded
environment with deterministic execution. To do so, the executor provides a Executor::step()
method that polls all non-blocked tasks exactly once. The executor also provides events
that can be waited upon. These events are referred to by the EventHandle
type which is
instantiated by calling Executor::create_event_handle()
, and can be waited on by
creating EventFuture
by calling the Executor::event()
method. They can be activated
by calling the Executor::notify_event()
method.
§Example
let executor = Executor::default();
let events = [executor.create_event_handle(), executor.create_event_handle()];
async fn wait_event(events: [EventHandle; 2], executor: Executor) {
executor.event(&events[0]).await;
executor.event(&events[1]).await;
}
executor.spawn(wait_event(events.clone(), executor.clone()));
assert_eq!(executor.step(), true);
assert_eq!(executor.step(), true);
executor.notify_event(&events[0]);
assert_eq!(executor.step(), true);
executor.notify_event(&events[1]);
assert_eq!(executor.step(), false);
Structs§
- Event
Future - A future to await an event
- Event
Handle - A handle for an event, can be kept and cloned around
- Executor
- Single-threaded polling-based executor