summaryrefslogtreecommitdiffstats
path: root/futures/src/executor
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--futures/src/executor.rs13
-rw-r--r--futures/src/executor/async_std.rs2
-rw-r--r--futures/src/executor/null.rs2
-rw-r--r--futures/src/executor/thread_pool.rs1
-rw-r--r--futures/src/executor/tokio.rs1
5 files changed, 19 insertions, 0 deletions
diff --git a/futures/src/executor.rs b/futures/src/executor.rs
index b2ff043e..c2b9cc72 100644
--- a/futures/src/executor.rs
+++ b/futures/src/executor.rs
@@ -29,13 +29,26 @@ pub use wasm_bindgen::WasmBindgen;
use futures::Future;
+/// A type that can run futures.
pub trait Executor: Sized {
+ /// Creates a new [`Executor`].
+ ///
+ /// [`Executor`]: trait.Executor.html
fn new() -> Result<Self, futures::io::Error>
where
Self: Sized;
+ /// Spawns a future in the [`Executor`].
+ ///
+ /// [`Executor`]: trait.Executor.html
fn spawn(&self, future: impl Future<Output = ()> + Send + 'static);
+ /// Runs the given closure inside the [`Executor`].
+ ///
+ /// Some executors, like `tokio`, require some global state to be in place
+ /// before creating futures. This method can be leveraged to set up this
+ /// global state, call a function, restore the state, and obtain the result
+ /// of the call.
fn enter<R>(&self, f: impl FnOnce() -> R) -> R {
f()
}
diff --git a/futures/src/executor/async_std.rs b/futures/src/executor/async_std.rs
index b056b23d..641dfbd2 100644
--- a/futures/src/executor/async_std.rs
+++ b/futures/src/executor/async_std.rs
@@ -2,6 +2,8 @@ use crate::Executor;
use futures::Future;
+/// A type representing the `async-std` runtime.
+#[derive(Debug)]
pub struct AsyncStd;
impl Executor for AsyncStd {
diff --git a/futures/src/executor/null.rs b/futures/src/executor/null.rs
index 722073bb..6d5cf982 100644
--- a/futures/src/executor/null.rs
+++ b/futures/src/executor/null.rs
@@ -2,6 +2,8 @@ use crate::Executor;
use futures::Future;
+/// An executor that drops all the futures, instead of spawning them.
+#[derive(Debug)]
pub struct Null;
impl Executor for Null {
diff --git a/futures/src/executor/thread_pool.rs b/futures/src/executor/thread_pool.rs
index 6393d0d5..09cb4d21 100644
--- a/futures/src/executor/thread_pool.rs
+++ b/futures/src/executor/thread_pool.rs
@@ -2,6 +2,7 @@ use crate::Executor;
use futures::Future;
+/// A thread pool for futures.
pub type ThreadPool = futures::executor::ThreadPool;
impl Executor for futures::executor::ThreadPool {
diff --git a/futures/src/executor/tokio.rs b/futures/src/executor/tokio.rs
index aafa7e7b..4c609686 100644
--- a/futures/src/executor/tokio.rs
+++ b/futures/src/executor/tokio.rs
@@ -2,6 +2,7 @@ use crate::Executor;
use futures::Future;
+/// The `tokio` runtime.
pub type Tokio = tokio::runtime::Runtime;
impl Executor for Tokio {