1use mm1_common::errors::error_of::ErrorOf;
2use mm1_core::context::{ForkErrorKind, SendErrorKind};
3use mm1_proto_timer as t;
4
5pub trait TimerApi: Send + 'static {
6 type Timer: t::Timer<
7 Key = Self::Key,
8 Instant = Self::Instant,
9 Duration = Self::Duration,
10 Message = Self::Message,
11 >;
12
13 type Instant;
14 type Duration;
15 type Key;
16 type Message;
17
18 fn cancel(&mut self, key: Self::Key) -> impl Future<Output = Result<(), TimerError>> + Send;
19
20 fn schedule_once_at(
21 &mut self,
22 key: Self::Key,
23 at: Self::Instant,
24 msg: Self::Message,
25 ) -> impl Future<Output = Result<(), TimerError>> + Send;
26
27 fn schedule_once_after(
28 &mut self,
29 key: Self::Key,
30 after: Self::Duration,
31 msg: Self::Message,
32 ) -> impl Future<Output = Result<(), TimerError>> + Send;
33}
34
35#[derive(Debug, thiserror::Error)]
36pub enum TimerError {
37 #[error("fork: {}", _0)]
38 Fork(ErrorOf<ForkErrorKind>),
39 #[error("send: {}", _0)]
40 Send(ErrorOf<SendErrorKind>),
41}