issue = "50547")]
use fmt;
-use super::{Executor, Waker, LocalWaker};
+use super::{Spawn, Waker, LocalWaker};
/// Information about the currently-running task.
///
/// when performing a single `poll` step on a task.
pub struct Context<'a> {
local_waker: &'a LocalWaker,
- executor: &'a mut dyn Executor,
+ spawner: &'a mut dyn Spawn,
}
impl<'a> fmt::Debug for Context<'a> {
}
impl<'a> Context<'a> {
- /// Create a new task `Context` with the provided `local_waker`, `waker`, and `executor`.
+ /// Create a new task `Context` with the provided `local_waker`, `waker`,
+ /// and `spawner`.
#[inline]
- pub fn new(local_waker: &'a LocalWaker, executor: &'a mut dyn Executor) -> Context<'a> {
- Context {
- local_waker,
- executor,
- }
+ pub fn new(
+ local_waker: &'a LocalWaker,
+ spawner: &'a mut dyn Spawn,
+ ) -> Context<'a> {
+ Context { local_waker, spawner }
}
/// Get the `LocalWaker` associated with the current task.
unsafe { &*(self.local_waker as *const LocalWaker as *const Waker) }
}
- /// Get the default executor associated with this task.
+ /// Get the spawner associated with this task.
///
/// This method is useful primarily if you want to explicitly handle
/// spawn failures.
#[inline]
- pub fn executor(&mut self) -> &mut dyn Executor {
- self.executor
+ pub fn spawner(&mut self) -> &mut dyn Spawn {
+ self.spawner
}
- /// Produce a context like the current one, but using the given waker instead.
+ /// Produce a context like the current one, but using the given waker
+ /// instead.
///
/// This advanced method is primarily used when building "internal
/// schedulers" within a task, where you want to provide some customized
/// wakeup logic.
#[inline]
- pub fn with_waker<'b>(&'b mut self, local_waker: &'b LocalWaker) -> Context<'b> {
+ pub fn with_waker<'b>(
+ &'b mut self,
+ local_waker: &'b LocalWaker,
+ ) -> Context<'b> {
Context {
local_waker,
- executor: self.executor,
+ spawner: self.spawner,
}
}
- /// Produce a context like the current one, but using the given executor
+ /// Produce a context like the current one, but using the given spawner
/// instead.
///
/// This advanced method is primarily used when building "internal
/// schedulers" within a task.
#[inline]
- pub fn with_executor<'b, E>(&'b mut self, executor: &'b mut E) -> Context<'b>
- where E: Executor
- {
+ pub fn with_spawner<'b, Sp: Spawn>(
+ &'b mut self,
+ spawner: &'b mut Sp,
+ ) -> Context<'b> {
Context {
local_waker: self.local_waker,
- executor,
+ spawner,
}
}
}