From 90690702e1e4abab804ec91e8ff4183824bec436 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 20 Jan 2020 04:47:36 +0100 Subject: Add `Application::Executor` associated type --- futures/src/executor/async_std.rs | 15 +++++++++++++++ futures/src/executor/null.rs | 13 +++++++++++++ futures/src/executor/thread_pool.rs | 15 +++++++++++++++ futures/src/executor/tokio.rs | 19 +++++++++++++++++++ 4 files changed, 62 insertions(+) create mode 100644 futures/src/executor/async_std.rs create mode 100644 futures/src/executor/null.rs create mode 100644 futures/src/executor/thread_pool.rs create mode 100644 futures/src/executor/tokio.rs (limited to 'futures/src/executor') diff --git a/futures/src/executor/async_std.rs b/futures/src/executor/async_std.rs new file mode 100644 index 00000000..b056b23d --- /dev/null +++ b/futures/src/executor/async_std.rs @@ -0,0 +1,15 @@ +use crate::Executor; + +use futures::Future; + +pub struct AsyncStd; + +impl Executor for AsyncStd { + fn new() -> Result { + Ok(Self) + } + + fn spawn(&self, future: impl Future + Send + 'static) { + let _ = async_std::task::spawn(future); + } +} diff --git a/futures/src/executor/null.rs b/futures/src/executor/null.rs new file mode 100644 index 00000000..722073bb --- /dev/null +++ b/futures/src/executor/null.rs @@ -0,0 +1,13 @@ +use crate::Executor; + +use futures::Future; + +pub struct Null; + +impl Executor for Null { + fn new() -> Result { + Ok(Self) + } + + fn spawn(&self, _future: impl Future + Send + 'static) {} +} diff --git a/futures/src/executor/thread_pool.rs b/futures/src/executor/thread_pool.rs new file mode 100644 index 00000000..6393d0d5 --- /dev/null +++ b/futures/src/executor/thread_pool.rs @@ -0,0 +1,15 @@ +use crate::Executor; + +use futures::Future; + +pub type ThreadPool = futures::executor::ThreadPool; + +impl Executor for futures::executor::ThreadPool { + fn new() -> Result { + futures::executor::ThreadPool::new() + } + + fn spawn(&self, future: impl Future + Send + 'static) { + self.spawn_ok(future); + } +} diff --git a/futures/src/executor/tokio.rs b/futures/src/executor/tokio.rs new file mode 100644 index 00000000..aafa7e7b --- /dev/null +++ b/futures/src/executor/tokio.rs @@ -0,0 +1,19 @@ +use crate::Executor; + +use futures::Future; + +pub type Tokio = tokio::runtime::Runtime; + +impl Executor for Tokio { + fn new() -> Result { + tokio::runtime::Runtime::new() + } + + fn spawn(&self, future: impl Future + Send + 'static) { + let _ = tokio::runtime::Runtime::spawn(self, future); + } + + fn enter(&self, f: impl FnOnce() -> R) -> R { + tokio::runtime::Runtime::enter(self, f) + } +} -- cgit From 04086a90c9e933ebfb42de378054e1115b33529d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 20 Jan 2020 05:43:09 +0100 Subject: Implement `WasmBindgen` executor and reorganize --- futures/src/executor/wasm_bindgen.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 futures/src/executor/wasm_bindgen.rs (limited to 'futures/src/executor') diff --git a/futures/src/executor/wasm_bindgen.rs b/futures/src/executor/wasm_bindgen.rs new file mode 100644 index 00000000..70a8ea8e --- /dev/null +++ b/futures/src/executor/wasm_bindgen.rs @@ -0,0 +1,17 @@ +use crate::Executor; + +#[derive(Debug)] +pub struct WasmBindgen; + +impl Executor for WasmBindgen { + fn new() -> Result { + Ok(Self) + } + + fn spawn( + &self, + future: impl futures::Future + Send + 'static, + ) { + wasm_bindgen_futures::spawn_local(future); + } +} -- cgit From f14009601e270e43bdf29b8f4842cf136fbbd8b9 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 20 Jan 2020 09:49:17 +0100 Subject: Write documentation for `iced_futures` --- futures/src/executor/async_std.rs | 2 ++ futures/src/executor/null.rs | 2 ++ futures/src/executor/thread_pool.rs | 1 + futures/src/executor/tokio.rs | 1 + 4 files changed, 6 insertions(+) (limited to 'futures/src/executor') 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 { -- cgit From 7bb6411dfc6797c567a96ff940fc72f3a6747ff4 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 20 Jan 2020 10:39:17 +0100 Subject: Write documentation for `executor::WasmBindgen` --- futures/src/executor/wasm_bindgen.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'futures/src/executor') diff --git a/futures/src/executor/wasm_bindgen.rs b/futures/src/executor/wasm_bindgen.rs index 70a8ea8e..2a12a1c0 100644 --- a/futures/src/executor/wasm_bindgen.rs +++ b/futures/src/executor/wasm_bindgen.rs @@ -1,5 +1,6 @@ use crate::Executor; +/// A type representing a `wasm-bindgen-futures` runtime. #[derive(Debug)] pub struct WasmBindgen; -- cgit From 91d9d65a03ce9b211e4043726e7424949d314325 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 20 Jan 2020 10:49:25 +0100 Subject: Improve consistency in executor documentation --- futures/src/executor/async_std.rs | 2 +- futures/src/executor/thread_pool.rs | 2 +- futures/src/executor/tokio.rs | 2 +- futures/src/executor/wasm_bindgen.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'futures/src/executor') diff --git a/futures/src/executor/async_std.rs b/futures/src/executor/async_std.rs index 641dfbd2..27949e31 100644 --- a/futures/src/executor/async_std.rs +++ b/futures/src/executor/async_std.rs @@ -2,7 +2,7 @@ use crate::Executor; use futures::Future; -/// A type representing the `async-std` runtime. +/// An `async-std` runtime. #[derive(Debug)] pub struct AsyncStd; diff --git a/futures/src/executor/thread_pool.rs b/futures/src/executor/thread_pool.rs index 09cb4d21..1ec5bf69 100644 --- a/futures/src/executor/thread_pool.rs +++ b/futures/src/executor/thread_pool.rs @@ -2,7 +2,7 @@ use crate::Executor; use futures::Future; -/// A thread pool for futures. +/// A thread pool runtime 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 4c609686..20802ceb 100644 --- a/futures/src/executor/tokio.rs +++ b/futures/src/executor/tokio.rs @@ -2,7 +2,7 @@ use crate::Executor; use futures::Future; -/// The `tokio` runtime. +/// A `tokio` runtime. pub type Tokio = tokio::runtime::Runtime; impl Executor for Tokio { diff --git a/futures/src/executor/wasm_bindgen.rs b/futures/src/executor/wasm_bindgen.rs index 2a12a1c0..69b7c7e2 100644 --- a/futures/src/executor/wasm_bindgen.rs +++ b/futures/src/executor/wasm_bindgen.rs @@ -1,6 +1,6 @@ use crate::Executor; -/// A type representing a `wasm-bindgen-futures` runtime. +/// A `wasm-bindgen-futures` runtime. #[derive(Debug)] pub struct WasmBindgen; -- cgit