1 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 #![unstable(feature = "futures_api",
12 reason = "futures in libcore are unstable",
16 use future::{FutureObj, LocalFutureObj};
18 /// Spawns tasks that poll futures to completion onto its associated task
21 /// The term "task" refers to a kind of lightweight "thread". Task executors
22 /// are responsible for scheduling the execution of tasks on operating system
25 /// Spawns a new task with the given future. The future will be polled until
30 /// The executor may be unable to spawn tasks, either because it has
31 /// been shut down or is resource-constrained.
34 future: FutureObj<'static, ()>,
35 ) -> Result<(), SpawnObjError>;
37 /// Determines whether the executor is able to spawn new tasks.
41 /// An `Ok` return means the executor is *likely* (but not guaranteed)
42 /// to accept a subsequent spawn attempt. Likewise, an `Err` return
43 /// means that `spawn` is likely, but not guaranteed, to yield an error.
45 fn status(&self) -> Result<(), SpawnErrorKind> {
50 /// Provides the reason that an executor was unable to spawn.
51 pub struct SpawnErrorKind {
55 impl fmt::Debug for SpawnErrorKind {
56 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
57 f.debug_tuple("SpawnErrorKind")
64 /// Spawning is failing because the executor has been shut down.
65 pub fn shutdown() -> SpawnErrorKind {
66 SpawnErrorKind { _hidden: () }
69 /// Check whether this error is the `shutdown` error.
70 pub fn is_shutdown(&self) -> bool {
75 /// The result of a failed spawn
77 pub struct SpawnObjError {
79 pub kind: SpawnErrorKind,
81 /// The future for which spawning inside a task was attempted
82 pub future: FutureObj<'static, ()>,
85 /// The result of a failed spawn
87 pub struct SpawnLocalObjError {
89 pub kind: SpawnErrorKind,
91 /// The future for which spawning inside a task was attempted
92 pub future: LocalFutureObj<'static, ()>,