maplibre/platform/noweb/
scheduler.rs1use std::future::Future;
2
3use crate::io::scheduler::{ScheduleError, Scheduler};
4
5pub 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 #[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}