fluxion_runtime/impls/
tokio.rs1#[cfg(feature = "runtime-tokio")]
6use std::{sync::Arc, time::Duration};
7
8#[cfg(feature = "runtime-tokio")]
9use parking_lot::Mutex;
10
11#[cfg(feature = "runtime-tokio")]
12use crate::{runtime::Runtime, timer::Timer};
13
14#[cfg(feature = "runtime-tokio")]
15#[derive(Debug)]
16pub struct TokioRuntime;
17
18#[cfg(feature = "runtime-tokio")]
19impl Runtime for TokioRuntime {
20 type Mutex<T: ?Sized> = Arc<Mutex<T>>;
21 type Timer = TokioTimer;
22 type Instant = std::time::Instant;
23}
24
25#[cfg(feature = "runtime-tokio")]
26#[derive(Clone, Debug, Default)]
27pub struct TokioTimer;
28
29#[cfg(feature = "runtime-tokio")]
30impl Timer for TokioTimer {
31 type Sleep = tokio::time::Sleep;
32
33 type Instant = std::time::Instant;
34
35 fn sleep_future(&self, duration: Duration) -> Self::Sleep {
36 tokio::time::sleep(duration)
37 }
38
39 fn now(&self) -> Self::Instant {
40 std::time::Instant::now()
41 }
42}