macro_rules! spawn { (in $pool:expr, $($args:tt)*) => { ... }; ($($args:tt)*) => { ... }; }
Expand description
Utility macro to spawn functions.
Since a very common pattern is to pass multiple values to a spawned function by using tuples it can be cumbersome to repeat the arguments. This macro makes it possible to not repeat oneself. The first argument to the macro is a tuple of the arguments to pass, the second argument is the closure that should be invoked.
For each argument the following expressions are possible:
ident
: uses the local variableident
unchanged.ident => other
: serializesident
and deserializes intoother
*ident
: alias for*ident => ident
.mut ident
: alias forident => mut ident
.
Example:
let a = 42u32;
let b = 23u32;
let handle = procspawn::spawn!((a, mut b) || {
b += 1;
a + b
});
To spawn in a pool you need to pass the pool to it (prefixed with in
):
let a = 42u32;
let b = 23u32;
let handle = procspawn::spawn!(in pool, (a, mut b) || {
b += 1;
a + b
});