[−][src]Struct async_task::Task
A task reference that runs its future.
The Task
reference "owns" the task itself and is able to run it. Running consumes the
Task
reference and polls its internal future. If the future is still pending after getting
polled, the Task
reference simply won't exist until a Waker
notifies the task. If the
future completes, its result becomes available to the JoinHandle
.
When the task is woken, the Task
reference is recreated and passed to the schedule
function. In most executors, scheduling simply pushes the Task
reference into a queue of
runnable tasks.
If the Task
reference is dropped without being run, the task is cancelled. When cancelled,
the task won't be scheduled again even if a Waker
wakes it. It is possible for the
JoinHandle
to cancel while the Task
reference exists, in which case an attempt to run
the task won't do anything.
Methods
impl<T> Task<T>
[src]
pub fn schedule(self)
[src]
Schedules the task.
This is a convenience method that simply reschedules the task by passing it to its schedule function.
If the task is cancelled, this method won't do anything.
pub fn run(self)
[src]
Runs the task.
This method polls the task's future. If the future completes, its result will become
available to the JoinHandle
. And if the future is still pending, the task will have to
be woken in order to be rescheduled and then run again.
If the task was cancelled by a JoinHandle
before it gets run, then this method won't do
anything.
It is possible that polling the future panics, in which case the panic will be propagated
into the caller. It is advised that invocations of this method are wrapped inside
catch_unwind
.
If a panic occurs, the task is automatically cancelled.
pub fn cancel(&self)
[src]
Cancels the task.
When cancelled, the task won't be scheduled again even if a Waker
wakes it. An attempt
to run it won't do anything.
pub fn tag(&self) -> &T
[src]
Returns a reference to the tag stored inside the task.
Trait Implementations
impl<T> Sync for Task<T>
[src]
impl<T> Drop for Task<T>
[src]
impl<T> Send for Task<T>
[src]
impl<T: Debug> Debug for Task<T>
[src]
Auto Trait Implementations
impl<T> Unpin for Task<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Task<T> where
T: UnwindSafe,
T: UnwindSafe,
impl<T> RefUnwindSafe for Task<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,