Skip to main content

Crate events

Crate events 

Source
Expand description

Async manual-reset and auto-reset events for multi-use signaling.

This crate provides two families of event primitives:

Each family comes in a thread-safe variant (Send + Sync) and a single-threaded Local variant for improved efficiency when thread safety is not required.

Events are lightweight cloneable handles. All clones from the same family share the same underlying state.

§Manual-reset example

use events::ManualResetEvent;

#[tokio::main]
async fn main() {
    let event = ManualResetEvent::boxed();
    let setter = event.clone();

    // Producer opens the gate from a background task.
    tokio::spawn(async move {
        setter.set();
    });

    // Consumer waits for the gate to open.
    event.wait().await;

    // The gate stays open — it must be explicitly closed.
    assert!(event.try_wait());
}

§Auto-reset example

use events::AutoResetEvent;

#[tokio::main]
async fn main() {
    let event = AutoResetEvent::boxed();
    let setter = event.clone();

    // Producer signals from a background task.
    tokio::spawn(async move {
        setter.set();
    });

    // Consumer waits for the signal.
    event.wait().await;

    // Signal was consumed.
    assert!(!event.try_wait());
}

Modules§

futures
Future types returned by event wait() methods.

Structs§

AutoResetEvent
Thread-safe async auto-reset event.
EmbeddedAutoResetEvent
Embedded-state container for AutoResetEvent.
EmbeddedLocalAutoResetEvent
Embedded-state container for LocalAutoResetEvent.
EmbeddedLocalManualResetEvent
Embedded-state container for LocalManualResetEvent.
EmbeddedManualResetEvent
Embedded-state container for ManualResetEvent.
LocalAutoResetEvent
Single-threaded async auto-reset event.
LocalManualResetEvent
Single-threaded async manual-reset event.
ManualResetEvent
Thread-safe async manual-reset event.
RawAutoResetEvent
Handle to an embedded AutoResetEvent.
RawLocalAutoResetEvent
Handle to an embedded LocalAutoResetEvent.
RawLocalManualResetEvent
Handle to an embedded LocalManualResetEvent.
RawManualResetEvent
Handle to an embedded ManualResetEvent.