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 --- src/native/executor.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/native/executor.rs (limited to 'src/native/executor.rs') diff --git a/src/native/executor.rs b/src/native/executor.rs new file mode 100644 index 00000000..68a1d280 --- /dev/null +++ b/src/native/executor.rs @@ -0,0 +1,23 @@ +//! Choose your preferred executor to power your application. +pub use iced_winit::{executor::Null, Executor}; +use iced_winit::{executor::ThreadPool, futures}; + +/// The default cross-platform executor. +/// +/// - On native platforms, it will use a `ThreadPool`. +/// - On the Web, it will use `wasm-bindgen-futures::spawn_local`. +#[derive(Debug)] +pub struct Default(ThreadPool); + +impl Executor for Default { + fn new() -> Result { + Ok(Default(ThreadPool::new()?)) + } + + fn spawn( + &self, + future: impl futures::Future + Send + 'static, + ) { + self.0.spawn(future); + } +} -- cgit