Struct Spawner

Source
pub struct Spawner<const N: usize, Q = MpMcQueue<Pin<Box<dyn Future<Output = ()> + Send + Sync + 'static>>, N>> { /* private fields */ }
Expand description

A simple task spawner and runner. It can queue multiple futures (tasks) and run them to completion.

Implementations§

Source§

impl<const N: usize> Spawner<N>

Source

pub const fn new() -> Self

Creates a new, empty Spawner.

Source

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

Spawns a new task. The provided future will be boxed, pinned, and added to the task queue.

§Arguments
  • future: The future to spawn. It must be 'static and output ().
Source

pub fn run_until_all_done(&self) -> Result<(), Error>

Runs all spawned tasks to completion. This method will block and continuously poll tasks in a round-robin fashion until all tasks have completed.

Note: If any task never completes (e.g., an infinite loop that never yields Poll::Ready), this method will also loop forever.

Trait Implementations§

Source§

impl<const N: usize> Default for Spawner<N>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<const N: usize, Q> Freeze for Spawner<N, Q>
where Q: Freeze,

§

impl<const N: usize, Q> RefUnwindSafe for Spawner<N, Q>
where Q: RefUnwindSafe,

§

impl<const N: usize, Q> Send for Spawner<N, Q>
where Q: Send,

§

impl<const N: usize, Q> Sync for Spawner<N, Q>
where Q: Sync,

§

impl<const N: usize, Q> Unpin for Spawner<N, Q>
where Q: Unpin,

§

impl<const N: usize, Q> UnwindSafe for Spawner<N, Q>
where Q: UnwindSafe,

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

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.