tsuki_scheduler/runtime/
tokio.rs1use std::future::Future;
2
3use crate::schedule::IntoSchedule;
4use crate::{Runtime, Task};
5
6#[derive(Debug, Default)]
13pub struct Tokio;
14
15impl Runtime for Tokio {
16 type Handle = tokio::task::JoinHandle<()>;
17}
18
19impl Tokio {
20 pub fn new() -> Self {
21 Self
22 }
23}
24
25impl Task<Tokio> {
26 pub fn tokio<S, F, Fut>(schedule: S, task: F) -> Self
36 where
37 S: IntoSchedule,
38 S::Output: Send + 'static,
39 F: Fn() -> Fut + Send + 'static,
40 Fut: Future<Output = ()> + Send + 'static,
41 {
42 Task {
43 schedule: Box::new(schedule.into_schedule()),
44 run: Box::new(move |_: _, _: _| tokio::task::spawn(task())),
45 }
46 }
47}