[−][src]Struct async_task::Task
A task reference that runs its future.
At any moment in time, there is at most one Task
reference associated with a particular
task. 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 a task is woken up, its 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 getting run, the task is automatically 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 up in order to be rescheduled and 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.
pub fn into_raw(self) -> *const T
[src]
Converts this task into a raw pointer to the tag.
pub unsafe fn from_raw(raw: *const T) -> Task<T>
[src]
Converts a raw pointer to the tag into a task.
This method should only be used with raw pointers returned from into_raw
.
pub fn waker(&self) -> Waker
[src]
Returns a waker associated with this task.
Trait Implementations
impl<T: Debug> Debug for Task<T>
[src]
impl<T> Drop for Task<T>
[src]
impl<T> Send for Task<T>
[src]
impl<T> Sync for Task<T>
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
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> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
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>,