Function lunatic_process::spawn

source ·
pub fn spawn<T, F, K, R>(
    env: Arc<dyn Environment>,
    func: F
) -> (JoinHandle<Result<T>>, NativeProcess)where
    T: Send + 'static,
    R: Into<ExecutionResult<T>> + 'static,
    K: Future<Output = R> + Send + 'static,
    F: FnOnce(NativeProcess, MessageMailbox) -> K,
Expand description

Spawns a process from a closure.

Example:

use std::sync::Arc;
let env = Arc::new(lunatic_process::env::LunaticEnvironment::new(1));
let _proc = lunatic_process::spawn(env, |_this, mailbox| async move {
    // Wait on a message with the tag `27`.
    mailbox.pop(Some(&[27])).await;
    // TODO: Needs to return ExecutionResult. Probably the `new` function will need to be adjusted
    Ok(())
});