async_repeater/entry.rs
1use std::fmt::Debug;
2use std::hash::Hash;
3use std::time::Duration;
4
5use crate::Delay;
6
7/// Entry for the [`Repeater`](crate::Repeater)
8pub trait RepeaterEntry {
9 /// The type of key
10 type Key: Hash + Eq + Unpin + Send + Debug;
11
12 /// Duration after which the entry should be repeated
13 fn interval(&self) -> Duration;
14
15 /// Duration after which the first repetition is run
16 ///
17 /// An example: It's 2:57pm and we want to start a repetition with an interval of 60 seconds,
18 /// but also want to wait until it's exactly 3pm.
19 /// We'd either set the delay to be relative 180 seconds or specify the absolute unix time stamp.
20 ///
21 /// If not implemented, it returns Delay::None starting the repetition instantly
22 fn delay(&self) -> Delay {
23 Delay::None
24 }
25
26 /// To identify the entry.
27 ///
28 /// We don't want to store the whole entry in the underlying queue,
29 /// but only a key
30 fn key(&self) -> Self::Key;
31}