Skip to content

A simple, specialized channel type for beaming data out of a newly spawned thread

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

WilliamVenner/threadbeam

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

crates.io docs.rs license

threadbeam

A simple, specialized channel type for beaming data out of a newly spawned thread.

Usage

First, add threadbeam to your crate's dependencies in Cargo.toml:

[dependencies]
threadbeam = "0"

Examples

let (tx, rx) = threadbeam::channel();

std::thread::spawn(move || {
    tx.send(String::from("Hello, world!"));
});

let hello = rx.recv();
assert_eq!(hello.as_deref(), Some("Hello, world!"));
let (hello, thread) = threadbeam::spawn(move |tx| {
    tx.send(String::from("Hello, world!"));
    // your code...
    String::from("Thread completed!")
});

assert_eq!(hello.as_deref(), Some("Hello, world!"));
assert_eq!(thread.join().ok().as_deref(), Some("Thread completed!"));

To use parking_lot instead of the standard library's implementations of Condvar and Mutex, enable the parking_lot feature in your Cargo.toml:

[dependencies]
threadbeam = { version = "0", features = ["parking_lot"] }

no_std via spin

For no_std environments, enable the no_std feature in your Cargo.toml:

This will use spin as the provider of the Mutex implementation.

[dependencies]
threadbeam = { version = "0", features = ["no_std"] }

About

A simple, specialized channel type for beaming data out of a newly spawned thread

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Languages