Skip to main content

Scope

Struct Scope 

Source
pub struct Scope<'scope, 'env, TaskResult>
where TaskResult: Send + 'env,
{ /* private fields */ }
Expand description

A handle passed to the closure in scope, allowing the spawning of scoped tasks and interaction with the set.

This handle wraps a mutable reference to the ScopedJoinSet, ensuring exclusive access to the set for operations like spawning and joining.

Implementations§

Source§

impl<'scope, 'env, TaskResult> Scope<'scope, 'env, TaskResult>
where TaskResult: Send + 'env,

Source

pub fn spawn<F>(&mut self, future: F)
where F: Future<Output = TaskResult> + Send + 'env,

Spawns a future into the scope.

This method is synchronous and non-blocking.

Source

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

Waits for the next task to complete.

Source

pub fn try_join_next(&mut self) -> Option<Result<TaskResult, JoinError>>

Tries to join the next task without blocking.

Source

pub fn is_empty(&self) -> bool

Returns true if the set is empty.

Source

pub fn len(&self) -> usize

Returns the number of tasks in the set.

Source

pub fn abort_all(&mut self)

Aborts all tasks.

Source

pub async fn join_all(&mut self) -> Vec<Result<TaskResult, JoinError>>

Joins all tasks and returns their results.

Auto Trait Implementations§

§

impl<'scope, 'env, TaskResult> !UnwindSafe for Scope<'scope, 'env, TaskResult>

§

impl<'scope, 'env, TaskResult> Freeze for Scope<'scope, 'env, TaskResult>
where &'scope mut ScopedJoinSet<'env, TaskResult>: Freeze,

§

impl<'scope, 'env, TaskResult> RefUnwindSafe for Scope<'scope, 'env, TaskResult>
where &'scope mut ScopedJoinSet<'env, TaskResult>: RefUnwindSafe,

§

impl<'scope, 'env, TaskResult> Send for Scope<'scope, 'env, TaskResult>
where &'scope mut ScopedJoinSet<'env, TaskResult>: Send,

§

impl<'scope, 'env, TaskResult> Sync for Scope<'scope, 'env, TaskResult>
where &'scope mut ScopedJoinSet<'env, TaskResult>: Sync,

§

impl<'scope, 'env, TaskResult> Unpin for Scope<'scope, 'env, TaskResult>
where &'scope mut ScopedJoinSet<'env, TaskResult>: Unpin,

§

impl<'scope, 'env, TaskResult> UnsafeUnpin for Scope<'scope, 'env, TaskResult>
where &'scope mut ScopedJoinSet<'env, TaskResult>: UnsafeUnpin,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.