Tasker

Struct Tasker 

Source
pub struct Tasker { /* private fields */ }
Expand description

Manages a group of tasks.

See library-level documentation.

Implementations§

Source§

impl Tasker

Source

pub fn new() -> Self

Constructs and empty task set.

Source

pub fn add_handle(&self, handle: JoinHandle<()>)

Add a tokio task handle to the task group.

It is your responsibility to make sure the task is stopped by this group’s Stopper future.

Source

pub fn spawn<F>(&self, future: F)
where F: Future + Send + 'static, F::Output: Send + 'static,

Spawn a !Send future the local task set and add its handle to the task group.

It is your responsibility to make sure the task is stopped by this group’s Stopper future.

Source

pub fn spawn_local<F>(&self, future: F)
where F: Future + 'static, F::Output: 'static,

Spawn a tokio task and add its handle to the task group. See tokio::task::spawn_local().

It is your responsibility to make sure the task is stopped by this group’s Stopper future.

Source

pub fn stopper(&self) -> Stopper

Dispense a Stopper, a future that will resolve once .stop() is called on any Tasker (or signaller Signaller) clone.

The Stopper future can be used with our .unless() extension to stop Futures, with .take_until() to stop Streams, as part of tokio::select!(), and similar…

Source

pub fn stop(&self) -> bool

Stop the tasks in the group.

This will resolve all Stopper futures (including ones obtained after this call).

Returns true if this was the first effective stop call or false if the group was already signalled to stop.

Source

pub fn signaller(&self) -> Signaller

Dispense a Signaller, a Tasker clone which can be used to signal stopping, but doesn’t require dropping or calling finish().

Source

pub fn is_stopped(&self) -> bool

true if stopping was already signalled.

Source

pub fn num_tasks(&self) -> usize

Number of tasks currently belonging to this task group.

Source

pub async fn join(self)

Join all the tasks in the group.

This function will panic if any of the tasks panicked. Use try_join() if you need to handle task panics yourself.

Note that join() will only return once all other Tasker clones are finished (via finish() or drop).

Source

pub async fn try_join(self) -> Vec<Result<(), JoinError>>

Join all the tasks in the group, returning a vector of join results (ie. results of tokio’s JoinHandle).

Note that try_join() will only return once all other Tasker clones are finished (via finish() or drop).

Source

pub fn join_stream(self) -> JoinStream

Returns a Stream which yields join results as they become available, ie. as the tasks terminate.

If any of the tasks terminates earlier than others, such as due to a panic, its result should be readily avialable through this stream.

The join stream stops after all tasks are joined and all other Tasker clones are finished (via finish() or drop).

Source

pub fn finish(self)

Mark this Tasker clone as finished.

This has the same effect as dropping the clone, but is more explicit. This lets the task group know that no new tasks will be added through this clone.

All Tasker clones need to be finished/dropped in order for .join() to be able to join all the tasks.

Use .signaller() to get a special Tasker clone that doesn’t need to be dropped and can be used to .stop() the task group.

Source

pub fn poll_join(&self) -> usize

Poll tasks once and join those that are finished.

Handles to tasks that are finished executing will be removed from the internal storage.

Returns the number of tasks that were joined.

This function will panic if any of the tasks panicked. Use try_poll_join() if you need to handle task panics yourself.

Source

pub fn try_poll_join(&self) -> Vec<Result<(), JoinError>>

Poll tasks once and join those that are already done.

Handles to tasks that are already finished executing will be joined and removed from the internal storage.

Returns vector of join results of tasks that were joined (may be empty if no tasks could’ve been joined).

Trait Implementations§

Source§

impl Clone for Tasker

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Tasker

Source§

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

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

impl Default for Tasker

Source§

fn default() -> Self

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

impl Drop for Tasker

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl Freeze for Tasker

§

impl !RefUnwindSafe for Tasker

§

impl Send for Tasker

§

impl Sync for Tasker

§

impl Unpin for Tasker

§

impl !UnwindSafe for Tasker

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

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