#async #signal #channel #once #fuse

fuze

A mechanism to wait for a single signal which can be checked at any time

3 stable releases

3.0.0 Jul 22, 2021
2.0.0 Jul 19, 2021
1.0.0 Jul 15, 2021

#1040 in Concurrency

Apache-2.0 OR MIT

10KB
86 lines

Fuze

A mechanism to wait for a single signal which can be checked at any time.

A Fuze can be checked synchronously, and will show up as burnt only once it’s been burnt. It can be awaited while it’s unburnt, and it can be Cloned and used without mut at any time.

Useful for exit conditions and as a one-off no-payload channel.

use fuze::Fuze;
use async_std::task;
use std::time::Duration;

let f1 = Fuze::new();

let f2 = f1.clone();
task::block_on(async move {
   println!("Halo!");

  	task::spawn(async move {
  		task::sleep(Duration::from_secs(1)).await;
  		f3.burn();
  	});

  	f2.wait().await;
   println!("Adios!");
});

lib.rs:

Fuzes are mechanisms to wait for a single signal which can be checked at any time.

This crate has an Async-std (default) and a Tokio implementation:

Async-std

fuze = "3.0.0"

Tokio

fuze = { version = "3.0.0", default-features = false, features = ["tokio"] }

Both implementations can co-exist (both features can be enabled at the same time) and the API is identical, but the top-level re-export will prefer the async-std version. Disabling both features will not compile.

Dependencies

~4–16MB
~194K SLoC