diff options
Diffstat (limited to '')
-rw-r--r-- | futures/Cargo.toml | 23 | ||||
-rw-r--r-- | futures/src/command.rs (renamed from core/src/command.rs) | 0 | ||||
-rw-r--r-- | futures/src/lib.rs | 8 | ||||
-rw-r--r-- | futures/src/runtime.rs (renamed from core/src/runtime.rs) | 13 | ||||
-rw-r--r-- | futures/src/runtime/executor.rs | 26 | ||||
-rw-r--r-- | futures/src/subscription.rs (renamed from core/src/subscription.rs) | 0 | ||||
-rw-r--r-- | futures/src/subscription/tracker.rs (renamed from core/src/subscription/tracker.rs) | 0 |
7 files changed, 66 insertions, 4 deletions
diff --git a/futures/Cargo.toml b/futures/Cargo.toml new file mode 100644 index 00000000..fe0d378c --- /dev/null +++ b/futures/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "iced_futures" +version = "0.1.0-alpha" +authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"] +edition = "2018" +description = "Commands, subscriptions, and runtimes for Iced" +license = "MIT" +repository = "https://github.com/hecrj/iced" +documentation = "https://docs.rs/iced_futures" +keywords = ["gui", "ui", "graphics", "interface", "futures"] +categories = ["gui"] + +[dependencies] +log = "0.4" + +[dependencies.futures] +version = "0.3" +features = ["thread-pool"] + +[dependencies.tokio] +version = "0.2" +optional = true +features = ["rt-core"] diff --git a/core/src/command.rs b/futures/src/command.rs index e7885fb8..e7885fb8 100644 --- a/core/src/command.rs +++ b/futures/src/command.rs diff --git a/futures/src/lib.rs b/futures/src/lib.rs new file mode 100644 index 00000000..f6bcf85a --- /dev/null +++ b/futures/src/lib.rs @@ -0,0 +1,8 @@ +mod command; + +pub mod runtime; +pub mod subscription; + +pub use command::Command; +pub use runtime::Runtime; +pub use subscription::Subscription; diff --git a/core/src/runtime.rs b/futures/src/runtime.rs index 31234d11..bc1ad8ac 100644 --- a/core/src/runtime.rs +++ b/futures/src/runtime.rs @@ -1,3 +1,4 @@ +//! Run commands and subscriptions. mod executor; pub use executor::Executor; @@ -10,8 +11,8 @@ use std::marker::PhantomData; #[derive(Debug)] pub struct Runtime<Hasher, Event, Executor, Receiver, Message> { executor: Executor, - subscriptions: subscription::Tracker<Hasher, Event>, receiver: Receiver, + subscriptions: subscription::Tracker<Hasher, Event>, _message: PhantomData<Message>, } @@ -28,15 +29,19 @@ where + 'static, Message: Send + 'static, { - pub fn new(receiver: Receiver) -> Self { + pub fn new(executor: Executor, receiver: Receiver) -> Self { Self { - executor: Executor::new(), - subscriptions: subscription::Tracker::new(), + executor, receiver, + subscriptions: subscription::Tracker::new(), _message: PhantomData, } } + pub fn enter<R>(&self, f: impl FnOnce() -> R) -> R { + self.executor.enter(f) + } + pub fn spawn(&mut self, command: Command<Message>) { use futures::{FutureExt, SinkExt}; diff --git a/futures/src/runtime/executor.rs b/futures/src/runtime/executor.rs new file mode 100644 index 00000000..855aa105 --- /dev/null +++ b/futures/src/runtime/executor.rs @@ -0,0 +1,26 @@ +use futures::Future; + +pub trait Executor { + fn spawn(&self, future: impl Future<Output = ()> + Send + 'static); + + fn enter<R>(&self, f: impl FnOnce() -> R) -> R { + f() + } +} + +impl Executor for futures::executor::ThreadPool { + fn spawn(&self, future: impl Future<Output = ()> + Send + 'static) { + self.spawn_ok(future); + } +} + +#[cfg(feature = "tokio")] +impl Executor for tokio::runtime::Runtime { + fn spawn(&self, future: impl Future<Output = ()> + Send + 'static) { + let _ = tokio::runtime::Runtime::spawn(self, future); + } + + fn enter<R>(&self, f: impl FnOnce() -> R) -> R { + tokio::runtime::Runtime::enter(self, f) + } +} diff --git a/core/src/subscription.rs b/futures/src/subscription.rs index 87e51e48..87e51e48 100644 --- a/core/src/subscription.rs +++ b/futures/src/subscription.rs diff --git a/core/src/subscription/tracker.rs b/futures/src/subscription/tracker.rs index a942b619..a942b619 100644 --- a/core/src/subscription/tracker.rs +++ b/futures/src/subscription/tracker.rs |