pub struct Task { /* private fields */ }
Expand description
An asynchronous task reference
Stakker provides only a very thin wrapping to enable tasks.
Full support is provided in a separate crate
(stakker_async_await). A task is represented as an
implementation of the TaskTrait
trait
which is called when the task needs to be resumed. It is expected
that even if the task cannot advance, it will accept a spurious
call gracefully. Spurious calls may be generated for example if
the task is woken from another thread.
It is guaranteed that the task is resumed directly from the main
loop, not within any actor call nor any deeper down the stack.
This may be important in order to avoid RefCell
panics, or to
allow the use of UnsafeCell
. Internally this is statically
guaranteed by using an ActorCell
to wrap the closure. This code
also handles the pinning required for running futures.
Deeper down the stack whilst the task is running, it is possible
to get a reference to the running task by using
Task::from_context
. This may be
used to implement efficient same-thread wakers.
Implementations§
source§impl Task
impl Task
sourcepub fn new(core: &mut Core, inner: impl TaskTrait + 'static) -> Self
pub fn new(core: &mut Core, inner: impl TaskTrait + 'static) -> Self
Create a new task from an implementation of the
TaskTrait
, and return a reference to
it. (Task
is like an Rc
reference to the task.) The
resume
method will be called each time the task needs to be
resumed.