summaryrefslogtreecommitdiffstats
path: root/src/native/executor.rs
blob: 68a1d280e272272fbcb7301f5372cf9f7dac0a6a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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<Self, futures::io::Error> {
        Ok(Default(ThreadPool::new()?))
    }

    fn spawn(
        &self,
        future: impl futures::Future<Output = ()> + Send + 'static,
    ) {
        self.0.spawn(future);
    }
}