Skip to main content

TaskCx

Struct TaskCx 

Source
pub struct TaskCx<Msg> { /* private fields */ }
Expand description

What running work can do: report progress, send messages, notice cancellation and sleep.

Implementations§

Source§

impl<Msg: Send + 'static> TaskCx<Msg>

Source

pub fn id(&self) -> TaskId

The running task.

Source

pub fn progress(&self, fraction: f32)

Reports the completed share, from 0 to 1.

Source

pub fn note(&self, note: impl Into<String>)

Describes the current step, e.g. “pushing layers”.

Source

pub fn send(&self, message: Msg)

Delivers message to the application while the work goes on, e.g. a log line.

Source

pub fn is_cancelled(&self) -> bool

Whether the application asked this task to stop. Long work should check it and return.

Source

pub fn sleep(&self, duration: Duration) -> bool

Waits duration, waking early when the task is cancelled. Returns false when it was cancelled. In tests the harness’s fake clock decides when the sleep ends.

Source

pub fn recv<T>(&self, rx: &Receiver<T>) -> Option<T>

Waits for the next item from rx, the receiving end of a channel another thread feeds, such as a connection handing over what it read. Returns None when the task is cancelled (which wins over an item already waiting) or when every sender is gone and nothing is left. A cancel reaches a waiting task within 50 ms: a standard channel wakes only for its senders, so the wait looks at the cancel in slices.

In a Harness a task waiting here rests like one asleep, so no step of the harness waits for it. An item sent from the test wakes it on its own thread; the harness applies what the task then sends at a later step, such as advance.

Source

pub fn recv_timeout<T>( &self, rx: &Receiver<T>, timeout: Duration, ) -> Result<T, RecvWait>

Like TaskCx::recv, giving up after timeout, and telling why no item came. In a Harness the timeout runs on the fake clock, like TaskCx::sleep.

§Errors

RecvWait::Timeout when timeout passed without an item, RecvWait::Cancelled when the task was cancelled and RecvWait::Closed when every sender is gone and nothing is left to receive.

Auto Trait Implementations§

§

impl<Msg> !RefUnwindSafe for TaskCx<Msg>

§

impl<Msg> !UnwindSafe for TaskCx<Msg>

§

impl<Msg> Freeze for TaskCx<Msg>
where Arc<dyn Fn(Msg) + Send + Sync>: Freeze,

§

impl<Msg> Send for TaskCx<Msg>
where Arc<dyn Fn(Msg) + Send + Sync>: Send,

§

impl<Msg> Sync for TaskCx<Msg>
where Arc<dyn Fn(Msg) + Send + Sync>: Sync,

§

impl<Msg> Unpin for TaskCx<Msg>
where Arc<dyn Fn(Msg) + Send + Sync>: Unpin,

§

impl<Msg> UnsafeUnpin for TaskCx<Msg>
where Arc<dyn Fn(Msg) + Send + Sync>: 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.