Struct deno_unsync::JoinSet

source ·
pub struct JoinSet<T> { /* private fields */ }
Expand description

Wraps the tokio JoinSet to make it !Send-friendly and to make it easier and safer for us to poll while empty.

Implementations§

source§

impl<T: 'static> JoinSet<T>

source

pub fn spawn<F>(&mut self, task: F) -> AbortHandle
where F: Future<Output = T> + 'static, T: 'static,

Spawn the provided task on the JoinSet, returning an AbortHandle that can be used to remotely cancel the task.

The provided future will start running in the background immediately when this method is called, even if you don’t await anything on this JoinSet.

§Panics

This method panics if called outside of a Tokio runtime.

source

pub fn len(&self) -> usize

Returns the number of tasks currently in the JoinSet.

source

pub fn is_empty(&self) -> bool

Returns whether the JoinSet is empty.

source

pub fn poll_join_next( &mut self, cx: &mut Context<'_>, ) -> Poll<Result<T, JoinError>>

Waits until one of the tasks in the set completes and returns its output.

§Cancel Safety

This method is cancel safe. If join_next is used as the event in a tokio::select! statement and some other branch completes first, it is guaranteed that no tasks were removed from this JoinSet.

source

pub async fn join_next(&mut self) -> Option<Result<T, JoinError>>

Waits until one of the tasks in the set completes and returns its output.

Returns None if the set is empty.

§Cancel Safety

This method is cancel safe. If join_next is used as the event in a tokio::select! statement and some other branch completes first, it is guaranteed that no tasks were removed from this JoinSet.

source

pub fn abort_all(&mut self)

Aborts all tasks on this JoinSet.

This does not remove the tasks from the JoinSet. To wait for the tasks to complete cancellation, you should call join_next in a loop until the JoinSet is empty.

source

pub fn detach_all(&mut self)

Removes all tasks from this JoinSet without aborting them.

The tasks removed by this call will continue to run in the background even if the JoinSet is dropped.

Trait Implementations§

source§

impl<T> Default for JoinSet<T>

source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<T> Freeze for JoinSet<T>

§

impl<T> RefUnwindSafe for JoinSet<T>

§

impl<T> Send for JoinSet<T>

§

impl<T> Sync for JoinSet<T>

§

impl<T> Unpin for JoinSet<T>

§

impl<T> UnwindSafe for JoinSet<T>

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

§

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

§

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.