Lifetime Thread

A thread with a lifetime. Divide a value into master and slave. After the lifetime of the master value ends, the slave value will not be accessible.


Crates.io version Download docs.rs docs ci


Introduction

A thread with a lifetime. Divide a value into master and slave. After the lifetime of the master value ends, the slave value will not be accessible.

scenes to be used:

Basic usage

```rust use std::{thread, time::Duration};

[test]

fn itworks() { let s = String::from("xxx"); let outer = lifetimethread::spawn(s, |inner| { println!("begin"); while let Some(t) = inner.get() { println!("ok! {}", t); asserteq!(t, "xxx") } println!("over") }); thread::sleep(Duration::frommillis(1)); assert_eq!(*outer, "xxx") } ```

output:

text begin ok! xxx ok! xxx ... ... ok! xxx over

Features

License

Licensed under either of

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