[][src]Struct async_scoped::Scope

pub struct Scope<'a, T> { /* fields omitted */ }

A scope to allow controlled spawning of non 'static futures. Futures can be spawned using spawn or spawn_cancellable methods.

Safety

This type uses Drop implementation to guarantee safety. It is not safe to forget this object unless it is driven to completion.

Methods

impl<'a, T: Send + 'static> Scope<'a, T>[src]

pub unsafe fn create() -> Self[src]

Create a Scope object.

This function is unsafe as futs may hold futures which have to be manually driven to completion.

pub fn spawn<F: Future<Output = T> + Send + 'a>(&mut self, f: F)[src]

Spawn a future with async_std::task::spawn. The future is expected to be driven to completion before 'a expires.

pub fn spawn_cancellable<F: Future<Output = T> + Send + 'a, Fu: FnOnce() -> T + Send + 'a>(
    &mut self,
    f: F,
    default: Fu
)
[src]

Spawn a cancellable future with async_std::task::spawn

The future is cancelled if the Scope is dropped pre-maturely. It can also be cancelled by explicitly calling (and awaiting) the cancel method.

impl<'a, T> Scope<'a, T>[src]

pub async fn cancel<'_>(&'_ self)[src]

Cancel all futures spawned with cancellation.

pub fn len(&self) -> usize[src]

Total number of futures spawned in this scope.

pub fn remaining(&self) -> usize[src]

Number of futures remaining in this scope.

pub async fn collect<'_>(&'_ mut self) -> Vec<T>[src]

A slighly optimized collect on the stream. Also useful when we can not move out of self.

Trait Implementations

impl<'a, T> Drop for Scope<'a, T>[src]

impl<'a, T> PinnedDrop for Scope<'a, T>[src]

impl<'a, T> Stream for Scope<'a, T>[src]

type Item = T

Values yielded by the stream.

impl<'pin, 'a, T> Unpin for Scope<'a, T> where
    __Scope<'pin, 'a, T>: Unpin
[src]

Auto Trait Implementations

impl<'a, T> !RefUnwindSafe for Scope<'a, T>

impl<'a, T> Send for Scope<'a, T>

impl<'a, T> Sync for Scope<'a, T>

impl<'a, T> !UnwindSafe for Scope<'a, T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> StreamExt for T where
    T: Stream + ?Sized
[src]

impl<T> StreamExt for T where
    T: Stream + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<S, T, E> TryStream for S where
    S: Stream<Item = Result<T, E>> + ?Sized
[src]

type Ok = T

The type of successful values yielded by this future

type Error = E

The type of failures yielded by this future

impl<S> TryStreamExt for S where
    S: TryStream + ?Sized
[src]