[][src]Function naja_async_runtime::rt::init

pub fn init(config: RtConfig) -> Result<(), RtErr>

Set the executor to use by default. Run this before calls to spawn. If you are a library author, don't call this unless you create the thread, otherwise it's up to client code to decide which executor to use. Just call spawn.

This is optional and if you don't set this, the default executor depends on whether the juliex feature is enabled for the crate. If it is, it is the default executor, otherwise it will be the local pool. If it's enabled and you still want the local pool, use this method.

Errors

This method will fail with RtErrKind::DoubleExecutorInit if you call it twice on the same thread or if you have called spawn and thus the executor has been initialized by default before you call init.

Example

use async_runtime::*;

rt::init( RtConfig::Local ).expect( "Set default executor" );

// ...spawn some tasks...
//
rt::spawn( async {} ).expect( "spawn future" );

// Important, otherwise the local executor does not poll. For the threadpool this is not necessary,
// as futures will be polled immediately after spawning them.
//
rt::run();