Function mioco::spawn [] [src]

pub fn spawn<F, T>(f: F) -> JoinHandle<T> where F: FnOnce() -> T, F: Send + 'static, T: Send + 'static

Spawn a mioco coroutine that executes the given function.

If called inside an existing mioco instance - spawn and run a new coroutine in it.

If called outside of existing mioco instance - spawn a new mioco instance in a separate thread or use existing mioco instance to run new mioco coroutine. The API intention is to guarantee:

  • This function does not block
  • The coroutine will execute in a mioco instance

the details on reusing existing mioco instances might change.

Any panics in the given function are caught and result in an Err that is available in the JoinHandle.