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>
impl<Msg: Send + 'static> TaskCx<Msg>
Sourcepub fn send(&self, message: Msg)
pub fn send(&self, message: Msg)
Delivers message to the application while the work goes on, e.g. a log line.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Whether the application asked this task to stop. Long work should check it and return.
Sourcepub fn sleep(&self, duration: Duration) -> bool
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.
Sourcepub fn recv<T>(&self, rx: &Receiver<T>) -> Option<T>
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.
Sourcepub fn recv_timeout<T>(
&self,
rx: &Receiver<T>,
timeout: Duration,
) -> Result<T, RecvWait>
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>
impl<Msg> Send for TaskCx<Msg>
impl<Msg> Sync for TaskCx<Msg>
impl<Msg> Unpin for TaskCx<Msg>
impl<Msg> UnsafeUnpin for TaskCx<Msg>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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