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>
impl<const N: usize> Spawner<N>
Sourcepub fn spawn<F>(&self, future: F) -> Result<(), Error>
pub fn spawn<F>(&self, future: F) -> Result<(), Error>
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'staticand output().
Sourcepub fn run_until_all_done(&self) -> Result<(), Error>
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more