pub struct TaskGroup { /* private fields */ }
Expand description

TaskGroup manages spawning and gracefully terminating asynchronous tasks on a multi-threaded Fuchsia executor, where individual tasks receive cancellation signals and are in control of terminating themselves. This allows the TaskGroup owner to await for completion of the tasks. TaskGroups can also be nested, allowing for independent cancellation of a child TaskGroup, or cancelling parent and child TaskGroups together (through cancelling the parent). Note that a dropped TaskGroup will cancel its own tasks, but not its childrens’ tasks. Hence, it is not recommended to rely on std::ops::drop, but rather to always use cancel() prior to destruction. (This might be changed in the future).

A TaskGroup has three implicit states: (1) active, (2) cancellation in progress and (3) complete. State (1) is reflected in the success of spawn, and (3) is reflected as the success of the cancel method. The possible state transitions are (1)->(2) and (2)->(3); note that once a TaskGroup is cancelled new tasks can never be spawned on it again.

Implementations§

source§

impl TaskGroup

source

pub fn new() -> Self

Create a new blank task group, ready for task spawning.

source

pub async fn spawn<F, Fut>(&self, f: F) -> Result<(), TaskGroupError>where F: FnOnce(TaskGroupCancel) -> Fut + Send + 'static, Fut: Future<Output = ()> + Send + 'static,

Spawn a task on the Fuchsia executor, with a handle to the cancellation future for this TaskGroup. Tasks are themselves responsible for polling the future, and if they do not complete as a response, the TaskGroup will not be able to cancel at all, so well-behaved tasks should poll or select over the cancellation signal whenever it is able to terminate itself gracefully.

If a TaskGroup cancellation is (2) already in progress or (3) completed, Err(TaskGroupError::AlreadyCancelled) will be returned.

source

pub fn cancel(&self) -> BoxFuture<'_, Result<(), TaskGroupError>>

Cancel ongoing tasks and await for their completion. Note that all tasks that were successfully added will be driven to completion. If more tasks are attempted to be spawn during the lifetime of this method, they will be rejected with an AlreadyCancelled error.

If this TaskGroup has children, they will be cancelled (concurrently, in no particular order) before the tasks of this TaskGroup are cancelled.

If a TaskGroup cancellation is (2) already in progress or (3) completed, Err(TaskGroupError::AlreadyCancelled) will be returned.

source

pub fn cancel_no_wait(&self) -> BoxFuture<'_, Result<(), TaskGroupError>>

Cancel ongoing tasks, but do not wait for their completion. Tasks are allowed to continue running to respond to the cancelation request. If more tasks are attempted to be spawn during the lifetime of this method, they will be rejected with an AlreadyCancelled error.

If this TaskGroup has children, they will be cancelled (concurrently, in no particular order) before the tasks of this TaskGroup are cancelled.

If a TaskGroup cancellation is (2) already in progress or (3) completed, Err(TaskGroupError::AlreadyCancelled) will be returned.

source

pub async fn create_child(&self) -> Result<Self, TaskGroupError>

Create a child TaskGroup that will be automatically cancelled when the parent is cancelled.

Trait Implementations§

source§

impl Clone for TaskGroup

source§

fn clone(&self) -> TaskGroup

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Encode<Ambiguous1> for T

§

unsafe fn encode( self, _encoder: &mut Encoder<'_>, _offset: usize, _depth: Depth ) -> Result<(), Error>

Encodes the object into the encoder’s buffers. Any handles stored in the object are swapped for Handle::INVALID. Read more
§

impl<T> Encode<Ambiguous2> for T

§

unsafe fn encode( self, _encoder: &mut Encoder<'_>, _offset: usize, _depth: Depth ) -> Result<(), Error>

Encodes the object into the encoder’s buffers. Any handles stored in the object are swapped for Handle::INVALID. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more