pub struct Builder<'a> { /* private fields */ }Expand description
Spawns tasks with options: a name, kept with the task’s id while the
task lives and shown to the runtime’s task hooks
(TaskMeta::name), and the worker to
place it on. Every spawn answers an error where the free functions
panic.
let task = nuclei::task::Builder::new().name("fetch").spawn(async { 7 })?;
assert_eq!(task.await, 7);Implementations§
Source§impl<'a> Builder<'a>
impl<'a> Builder<'a>
Sourcepub fn worker(self, worker: usize) -> Self
pub fn worker(self, worker: usize) -> Self
Places the task on worker worker of its runtime, where it stays, as
RuntimeHandle::spawn_on_worker
does. A spawn_local then needs to run on that
worker, and a spawn_blocking is refused: the
blocking pool runs no worker.
Sourcepub fn spawn_local<F>(self, future: F) -> Result<Task<F::Output>>
pub fn spawn_local<F>(self, future: F) -> Result<Task<F::Output>>
Spawns as spawn_local does.
§Errors
When this thread’s shard cannot start, and InvalidInput when a
worker is named that this thread does not run: a future that is not
Send cannot go to another thread.
Sourcepub fn spawn_blocking<F, T>(self, f: F) -> Result<Task<T>>
pub fn spawn_blocking<F, T>(self, f: F) -> Result<Task<T>>
Runs f on the blocking pool as spawn_blocking does.
§Errors
When the default runtime cannot start, and InvalidInput when a
worker is named.
Sourcepub fn spawn_on<F>(
self,
future: F,
handle: &RuntimeHandle,
) -> Result<Task<F::Output>>
pub fn spawn_on<F>( self, future: F, handle: &RuntimeHandle, ) -> Result<Task<F::Output>>
Spawns on the runtime handle refers to, as
RuntimeHandle::spawn does,
on the named worker if one is set.
§Errors
When this thread’s shard cannot start (the runtime has no worker
taking tasks), and InvalidInput when the named worker does not exist
or takes no new task.