Skip to main content

LocalAsyncScope

Struct LocalAsyncScope 

Source
pub struct LocalAsyncScope<'a> { /* private fields */ }
Available on crate feature alloc only.
Expand description

A LIFO stack of local asynchronous cleanup actions.

Each registration stores one boxed wrapper future. The cleanup factory is invoked only when that wrapper is first polled, and actions are awaited sequentially.

Dropping a pending LocalRun leaves its current action in the stack. A later run resumes it after any newer LIFO entries. Dropping the scope itself drops all remaining actions without polling them further.

Implementations§

Source§

impl<'a> LocalAsyncScope<'a>

Source

pub const fn new() -> Self

Creates an empty scope.

Source

pub fn with_capacity(capacity: usize) -> Self

Creates an empty scope with space for at least capacity actions.

Source

pub fn defer<F, Fut>(&mut self, action: F)
where F: FnOnce() -> Fut + 'a, Fut: Future<Output = ()> + 'a,

Queues a cleanup factory without invoking it.

Source

pub fn len(&self) -> usize

Returns the number of cleanup actions that have not completed.

Source

pub fn capacity(&self) -> usize

Returns the number of actions the scope can hold without reallocating.

Source

pub fn is_empty(&self) -> bool

Returns true when no cleanup actions remain.

Source

pub fn clear(&mut self)

Drops all queued actions without polling them further.

Source

pub fn run(&mut self) -> LocalRun<'_, 'a>

Borrows the scope and drains its actions in LIFO order.

Source

pub async fn finish(self)

Consumes the scope and runs its actions in LIFO order.

Dropping the returned future also drops every remaining action.

Trait Implementations§

Source§

impl Debug for LocalAsyncScope<'_>

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for LocalAsyncScope<'_>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for LocalAsyncScope<'a>

§

impl<'a> !Send for LocalAsyncScope<'a>

§

impl<'a> !Sync for LocalAsyncScope<'a>

§

impl<'a> !UnwindSafe for LocalAsyncScope<'a>

§

impl<'a> Freeze for LocalAsyncScope<'a>

§

impl<'a> Unpin for LocalAsyncScope<'a>

§

impl<'a> UnsafeUnpin for LocalAsyncScope<'a>

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.