An open API service indexing awesome lists of open source software.

https://github.com/rustonaut/fuseflag

A (not resettable) fuse/flag which can be shared between different threads
https://github.com/rustonaut/fuseflag

Last synced: about 1 year ago
JSON representation

A (not resettable) fuse/flag which can be shared between different threads

Awesome Lists containing this project

README

          

# fuseflag   [![Build Status](https://travis-ci.org/dathinab/fuseflag.svg?branch=master)](https://travis-ci.org/dathinab/fuseflag)

**A (not resettable) fuse/flag which can be shared between different threads**

---

Fuseflag provides a Fuse/Flag which can be shared (by cloning) between multiple threads.
The Fuse/Flag can be checked and burned, once burned it cannot be restored.

A additional functionality is a wrapper around `thread::spawn` which takes a closure
expecting a `FuseFlag` as single parameter and returns a Wrapper around `JoinHandle`
which burns the fuse before calling join.

## Example

```rust
extern crate fuseflag;

use std::time::Duration;
use std::thread::{sleep, spawn, JoinHandle};

use fuseflag::FuseFlag;

fn background_job(end_flag: FuseFlag, id: u64) -> JoinHandle<()> {
spawn(move || {
while end_flag.check() {
println!("\tbg-job({}): continues workin", id);
//Background work Work
sleep(Duration::from_millis(430*id));
}
println!("\tbg-job({}) stops running", id);
})
}

fn main() {
let end_fuse = FuseFlag::new();

let bg_guard = vec![
background_job(end_fuse.clone(), 1),
background_job(end_fuse.clone(), 2)
];

println!("running fake ui loop...");
//naturally a very nice ui called sleep ;)
sleep(Duration::from_secs(3));
println!("main loop ended: waiting for background jobs to stop");

//this will trigger .check() to return false (for ever from now on)
end_fuse.burn();

//join the threads
for guard in bg_guard {
guard.join().unwrap();
}
}
```

## License

Licensed under either of

* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://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.