MCPcopy Create free account
hub / github.com/smol-rs/event-listener

github.com/smol-rs/event-listener @v5.4.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v5.4.1 ↗ · + Follow
175 symbols 398 edges 9 files ⚖ MIT 46 documented · 26% 7 cross-repo links ● updated 3mo agov5.4.2 · 2026-07-27★ 5164 open issues

Browse by type

⨍ Functions 129◇ Types & classes 46
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

event-listener

Build License Cargo Documentation

Notify async tasks or threads.

This is a synchronization primitive similar to eventcounts invented by Dmitry Vyukov.

You can use this crate to turn non-blocking data structures into async or blocking data structures. See a simple mutex implementation that exposes an async and a blocking interface for acquiring locks.

Examples

Wait until another thread sets a boolean flag:

use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::thread;
use std::time::Duration;
use event_listener::Event;

let flag = Arc::new(AtomicBool::new(false));
let event = Arc::new(Event::new());

// Spawn a thread that will set the flag after 1 second.
thread::spawn({
    let flag = flag.clone();
    let event = event.clone();
    move || {
        // Wait for a second.
        thread::sleep(Duration::from_secs(1));

        // Set the flag.
        flag.store(true, Ordering::SeqCst);

        // Notify all listeners that the flag has been set.
        event.notify(usize::MAX);
    }
});

// Wait until the flag is set.
loop {
    // Check the flag.
    if flag.load(Ordering::SeqCst) {
        break;
    }

    // Start listening for events.
    let listener = event.listen();

    // Check the flag again after creating the listener.
    if flag.load(Ordering::SeqCst) {
        break;
    }

    // Wait for a notification and continue the loop.
    listener.wait();
}

License

Licensed under either of

  • Apache License, Version 2.0 (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
  • MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Extension points exported contracts — how you extend this code

browse all types & interfaces →

Core symbols most depended-on inside this repo

browse all functions →

Shape

Method 93
Function 36
Class 31
Interface 8
Enum 7

Languages

Rust100%

Modules by API surface

src/lib.rs48 symbols
src/slab.rs33 symbols
src/notify.rs25 symbols
src/intrusive.rs20 symbols
src/slab/node.rs16 symbols
examples/mutex.rs12 symbols
tests/notify.rs10 symbols
tests/loom.rs10 symbols
benches/bench.rs1 symbols

For agents

$ claude mcp add event-listener \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page