macro_rules! spawn {
    ($(&$config:ident,)? || $body:expr) => { ... };
    ($(&$config:ident,)? |$($argument:ident $(= $value:tt)? ),*| $body:expr) => { ... };
    ($(&$config:ident,)? |$($argument:ident $(= $value:block)? ),*| $body:expr) => { ... };
    ($(&$config:ident,)? |$mailbox:ident : Mailbox<$mailbox_ty:ty $( , $mailbox_s:ty )?>| $body:expr) => { ... };
    ($(&$config:ident,)? |$argument:ident, $mailbox:ident : Mailbox<$mailbox_ty:ty $( , $mailbox_s:ty )?>| $body:expr) => { ... };
}
Expand description

Helper macro for spawning processes.

The Process::spawn function can be too verbose for simple processes. This macro should cover most common cases of spawning a process from non-capturing closures.

Example

// Background process
spawn!(|| {});
// Mailbox process
spawn!(|_mailbox: Mailbox<()>| {});
// Capture local var
let local_var = "Hello".to_owned();
spawn!(|local_var| assert_eq!(local_var, "Hello"));
// Give variable during invocation
spawn!(|local_var = {"Hello".to_owned()}| assert_eq!(local_var, "Hello"));
// Background process with config
let config = ProcessConfig::new().unwrap();
spawn!(&config, || {});