iced_futures/
executor.rs

1//! Choose your preferred executor to power a runtime.
2use crate::MaybeSend;
3
4/// A type that can run futures.
5pub trait Executor: Sized {
6    /// Creates a new [`Executor`].
7    fn new() -> Result<Self, futures::io::Error>
8    where
9        Self: Sized;
10
11    /// Spawns a future in the [`Executor`].
12    fn spawn(&self, future: impl Future<Output = ()> + MaybeSend + 'static);
13
14    /// Runs a future to completion in the current thread within the [`Executor`].
15    #[cfg(not(target_arch = "wasm32"))]
16    fn block_on<T>(&self, future: impl Future<Output = T>) -> T;
17
18    /// Runs the given closure inside the [`Executor`].
19    ///
20    /// Some executors, like `tokio`, require some global state to be in place
21    /// before creating futures. This method can be leveraged to set up this
22    /// global state, call a function, restore the state, and obtain the result
23    /// of the call.
24    fn enter<R>(&self, f: impl FnOnce() -> R) -> R {
25        f()
26    }
27}