go

Macro go 

Source
macro_rules! go {
    ( $( $tokens:tt )+ ) => { ... };
}
Expand description

Spawns a thread to execute the given code. Any captured variables will be moved to the spawned thread.

The thread’s handle will be stored in thread-local storage until joined by join! or join_all!.

§Examples

use go_spawn::go;
use std::sync::{
    atomic::{AtomicI64, Ordering},
    Arc,
};

go!(expensive_background_work());

let counter = Arc::new(AtomicI64::new(0));
let copy_of_counter = counter.clone();

go! {
    for _ in 0..1_000_000 {
        copy_of_counter.fetch_add(1, Ordering::SeqCst);
    }
}