Skip to main content

Builder

Struct Builder 

Source
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>

Source

pub fn new() -> Self

A builder with no option set.

Source

pub fn name(self, name: &'a str) -> Self

Names the task.

Source

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.

Source

pub fn spawn<F>(self, future: F) -> Result<Task<F::Output>>
where F: Future + Send + 'static, F::Output: Send + 'static,

Spawns as spawn does, on the named worker if one is set.

§Errors

When the default runtime or this thread’s shard cannot start, and InvalidInput when the named worker does not exist or takes no new task.

Source

pub fn spawn_local<F>(self, future: F) -> Result<Task<F::Output>>
where F: Future + 'static, F::Output: 'static,

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.

Source

pub fn spawn_blocking<F, T>(self, f: F) -> Result<Task<T>>
where F: FnOnce() -> T + Send + 'static, T: Send + 'static,

Runs f on the blocking pool as spawn_blocking does.

§Errors

When the default runtime cannot start, and InvalidInput when a worker is named.

Source

pub fn spawn_on<F>( self, future: F, handle: &RuntimeHandle, ) -> Result<Task<F::Output>>
where F: Future + Send + 'static, F::Output: Send + 'static,

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.

Trait Implementations§

Source§

impl<'a> Clone for Builder<'a>

Source§

fn clone(&self) -> Builder<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for Builder<'a>

Source§

impl<'a> Debug for Builder<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Default for Builder<'a>

Source§

fn default() -> Builder<'a>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Builder<'a>

§

impl<'a> RefUnwindSafe for Builder<'a>

§

impl<'a> Send for Builder<'a>

§

impl<'a> Sync for Builder<'a>

§

impl<'a> Unpin for Builder<'a>

§

impl<'a> UnsafeUnpin for Builder<'a>

§

impl<'a> UnwindSafe for Builder<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> MaybeSend for T
where T: Send + ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.