task_control

Struct TaskControl

Source
pub struct TaskControl<T, S> { /* private fields */ }
Expand description

A task wrapper that runs the task asynchronously and provides access to its state.

Implementations§

Source§

impl<T: AsyncRun<S>, S: 'static + Send> TaskControl<T, S>

Source

pub fn new(task: T) -> Self

Creates the task control, taking the state for the task but not yet creating or starting it.

Source

pub fn has_state(&self) -> bool

Returns true if a task has been inserted.

Source

pub fn is_running(&self) -> bool

Returns true if a task is running.

Source

pub fn task(&self) -> &T

Gets the task.

Panics if the task is running.

Source

pub fn task_mut(&mut self) -> &mut T

Gets the task.

Panics if the task is running.

Source

pub fn state(&self) -> Option<&S>

Gets the transient task state.

Panics if the task is running.

Source

pub fn state_mut(&mut self) -> Option<&mut S>

Gets the transient task state.

Panics if the task is running.

Source

pub fn get(&self) -> (&T, Option<&S>)

Gets the task and its state.

Panics if the task is running.

Source

pub fn get_mut(&mut self) -> (&mut T, Option<&mut S>)

Gets the state and the task.

Panics if the task is running.

Source

pub fn into_inner(self) -> (T, Option<S>)

Retrieves the task and its state.

Panics if the task is running.

Source

pub fn update_with( &mut self, f: impl 'static + Send + FnOnce(&mut T, Option<&mut S>), )

Calls f against the task and its state.

If the task is running, then f will run remotely and will not necessarily finish before this routine returns.

Source

pub fn insert( &mut self, spawn: impl Spawn, name: impl Into<Arc<str>>, state: S, ) -> &mut S

Inserts the state the task object will use to run and starts the backing task, but does not start running it.

Source

pub fn start(&mut self) -> bool

Starts the task if it is not already running.

Returns true if the task is now running (even if it was previously running). Returns false if the task is not running (either because its state has not been inserted, or because it has already completed).

Source

pub async fn stop(&mut self) -> bool

Stops the task, waiting for it to be cancelled.

Returns true if the task was previously running. Returns false if the task was not running, not inserted, or had already completed.

Source

pub fn remove(&mut self) -> S

Removes the task state.

Panics if the task is not stopped.

Trait Implementations§

Source§

impl<T: InspectTask<S>, S> Inspect for TaskControl<T, S>

Source§

fn inspect(&self, req: Request<'_>)

Inspects the object.
Source§

impl<T: InspectTaskMut<U>, U> InspectMut for TaskControl<T, U>

Source§

fn inspect_mut(&mut self, req: Request<'_>)

Inspects the object.

Auto Trait Implementations§

§

impl<T, S> Freeze for TaskControl<T, S>

§

impl<T, S> !RefUnwindSafe for TaskControl<T, S>

§

impl<T, S> Send for TaskControl<T, S>
where T: Send, S: Send,

§

impl<T, S> Sync for TaskControl<T, S>
where T: Sync + Send, S: Sync + Send,

§

impl<T, S> Unpin for TaskControl<T, S>

§

impl<T, S> !UnwindSafe for TaskControl<T, S>

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.

§

impl<T> Instrument for T

§

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

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

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

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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