# schedule_method.rs - source
Source of the Rust file `maplibre/src/platform/noweb/schedule_method.rs`.
Keywords: rust, rustlang, rust-lang

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23

    use crate::error::Error;
    use crate::ScheduleMethod;
    use std::future::Future;
    use std::pin::Pin;

    /// Multi-threading with Tokio.
    pub struct TokioScheduleMethod;

    impl TokioScheduleMethod {
        pub fn new() -> Self {
            Self {}
        }
    }

    impl ScheduleMethod for TokioScheduleMethod {
        fn schedule<T>(&self, future_factory: impl FnOnce() -> T + Send + 'static) -> Result<(), Error>
        where
            T: Future<Output = ()> + Send + 'static,
        {
            tokio::task::spawn((future_factory)());
            Ok(())
        }
    }