Macro lunatic::spawn_link

source ·
macro_rules! spawn_link {
    ($(&$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) => { ... };
    (@task $(&$config:ident,)? || $body:expr) => { ... };
    (@task $(&$config:ident,)? |$($argument:ident $(= $value:block)? ),*| $body:expr) => { ... };
    (@task $(&$config:ident,)? |$($argument:ident $(= $value:tt)? ),*| $body:expr) => { ... };
    ($(&$config:ident,)? |$protocol:ident : Protocol<$proto_ty:ty>| $body:expr) => { ... };
    ($(&$config:ident,)? |$argument:ident, $protocol:ident : Protocol<$proto_ty:ty>| $body:expr) => { ... };
}
Expand description

Helper macro for spawning linked processes.

The Process::spawn_link 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_link!(|| {});
// Mailbox process
spawn_link!(|_mailbox: Mailbox<()>| {});
// Capture local var
let local_var = "Hello".to_owned();
spawn_link!(|local_var| assert_eq!(local_var, "Hello"));
// Give variable during invocation
spawn_link!(|local_var = {"Hello".to_owned()}| assert_eq!(local_var, "Hello"));
// Protocol, no capture
spawn_link!(|_proto: Protocol<End>| {});
// Protocol, capture local_var
let local_var = "Hello".to_owned();
spawn_link!(|local_var, _proto: Protocol<End>| assert_eq!(local_var, "Hello"));
// Background process with config
let config = ProcessConfig::new().unwrap();
spawn_link!(&config, || {});