waitx

Crates.iowaitx
lib.rswaitx
version0.1.1
created_at2025-07-19 22:49:09.473104+00
updated_at2025-07-26 17:34:37.050135+00
descriptionLightweight synchronization primitive for one-time ready/wait signaling with optional notification.
homepage
repositoryhttps://github.com/eschwart/waitx
max_upload_size
id1760586
size10,808
Evan Schwartzentruber (eschwart)

documentation

README

waitx

waitx is a minimal synchronization utility for signaling readiness between threads using a lightweight flag, a condition variable, and optional backoff. It provides a flexible alternative to channels or more heavyweight synchronization primitives when you just need to wait for a single "ready" event.

Features

  • Waiter: blocks until a flag is set, using backoff + condition variable.
  • Notifier: sets the flag and notifies a waiting thread.
  • Setter: sets the flag without notifying.
  • Spectator: reads the state without modifying it.
  • Lightweight and no_std-compatible (with alloc).
  • Built on parking_lot and crossbeam-utils.

Usage

Add to your Cargo.toml:

[dependencies]
waitx = "0.1"

Example

use std::thread;
use waitx::Waiter;

let waiter = Waiter::default();
let notifier = waiter.notifier();

let handle = thread::spawn(move || {
    println!("Worker waiting...");
    waiter.wait();
    println!("Worker resumed!");
});

std::thread::sleep(std::time::Duration::from_millis(100));
notifier.notify();
handle.join().unwrap();

When to Use

  • Use waitx when you want a simple signaling mechanism:
  • One thread signals readiness, another waits.
  • A flag is reused multiple times with resets.
  • You want fine control over notification vs. just setting state.

Crate Goals

  • Minimal API
  • Efficient signaling
  • No channels or locks unless needed
  • Readable and ergonomic code
Commit count: 0

cargo fmt