maplibre/platform/noweb/
scheduler.rs

1use std::future::Future;
2
3use crate::io::scheduler::{ScheduleError, Scheduler};
4
5/// Multi-threading with Tokio.
6pub struct TokioScheduler;
7
8impl TokioScheduler {
9    pub fn new() -> Self {
10        Self {}
11    }
12}
13
14impl Scheduler for TokioScheduler {
15    #[cfg(feature = "thread-safe-futures")]
16    fn schedule<T>(
17        &self,
18        future_factory: impl FnOnce() -> T + Send + 'static,
19    ) -> Result<(), ScheduleError>
20    where
21        T: Future<Output = ()> + Send + 'static,
22    {
23        tokio::task::spawn((future_factory)());
24        Ok(())
25    }
26
27    // FIXME: Provide a working implementation
28    #[cfg(not(feature = "thread-safe-futures"))]
29    fn schedule<T>(
30        &self,
31        _future_factory: impl FnOnce() -> T + 'static,
32    ) -> Result<(), ScheduleError>
33    where
34        T: Future<Output = ()> + 'static,
35    {
36        Ok(())
37    }
38}
39
40impl Default for TokioScheduler {
41    fn default() -> Self {
42        Self::new()
43    }
44}