Skip to content

Commit 0127704

Browse files
Rollup merge of rust-lang#52610 - MajorBreakfast:task-terminology, r=cramertj
Clarify what a task is Currently we call two distinct concepts "task": 1. The top-level future that is polled until completion 2. The lightweight "thread" that is responsible for polling the top-level future. What additional data beside the future is stored in this type varies between different `Executor` implementations. I'd prefer to return to the old formulation by @alexcrichton: ```rust /// A handle to a "task", which represents a single lightweight "thread" of /// execution driving a future to completion. pub struct Task { ``` Source: [`task_impl/mod.rs` in futures-rs 0.1](https://github.com/rust-lang-nursery/futures-rs/blob/1328fc9e8af5737183df477c7501e6ea24ff2053/src/task_impl/mod.rs#L49-L50) I think that this change will make it much easier to explain everything. r? @aturon @cramertj
2 parents e29f15b + eacfd72 commit 0127704

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

src/libcore/task/executor.rs

+18-12
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,27 @@ use future::{FutureObj, LocalFutureObj};
1717

1818
/// A task executor.
1919
///
20-
/// A *task* is a `()`-producing async value that runs at the top level, and will
21-
/// be `poll`ed until completion. It's also the unit at which wake-up
22-
/// notifications occur. Executors, such as thread pools, allow tasks to be
23-
/// spawned and are responsible for putting tasks onto ready queues when
24-
/// they are woken up, and polling them when they are ready.
20+
/// Futures are polled until completion by tasks, a kind of lightweight
21+
/// "thread". A *task executor* is responsible for the creation of these tasks
22+
/// and the coordination of their execution on real operating system threads. In
23+
/// particular, whenever a task signals that it can make further progress via a
24+
/// wake-up notification, it is the responsibility of the task executor to put
25+
/// the task into a queue to continue executing it, i.e. polling the future in
26+
/// it, later.
2527
pub trait Executor {
26-
/// Spawn the given task, polling it until completion.
28+
/// Spawns a new task with the given future. The future will be polled until
29+
/// completion.
2730
///
2831
/// # Errors
2932
///
3033
/// The executor may be unable to spawn tasks, either because it has
3134
/// been shut down or is resource-constrained.
32-
fn spawn_obj(&mut self, task: FutureObj<'static, ()>) -> Result<(), SpawnObjError>;
35+
fn spawn_obj(
36+
&mut self,
37+
future: FutureObj<'static, ()>,
38+
) -> Result<(), SpawnObjError>;
3339

34-
/// Determine whether the executor is able to spawn new tasks.
40+
/// Determines whether the executor is able to spawn new tasks.
3541
///
3642
/// # Returns
3743
///
@@ -75,8 +81,8 @@ pub struct SpawnObjError {
7581
/// The kind of error
7682
pub kind: SpawnErrorKind,
7783

78-
/// The task for which spawning was attempted
79-
pub task: FutureObj<'static, ()>,
84+
/// The future for which spawning inside a task was attempted
85+
pub future: FutureObj<'static, ()>,
8086
}
8187

8288
/// The result of a failed spawn
@@ -85,6 +91,6 @@ pub struct SpawnLocalObjError {
8591
/// The kind of error
8692
pub kind: SpawnErrorKind,
8793

88-
/// The task for which spawning was attempted
89-
pub task: LocalFutureObj<'static, ()>,
94+
/// The future for which spawning inside a task was attempted
95+
pub future: LocalFutureObj<'static, ()>,
9096
}

0 commit comments

Comments
 (0)