kayrx_timer/driver/
registration.rs1use crate::driver::Entry;
2use crate::{Duration, Error, Instant};
3
4use std::sync::Arc;
5use std::task::{self, Poll};
6
7#[derive(Debug)]
12pub(crate) struct Registration {
13 entry: Arc<Entry>,
14}
15
16impl Registration {
17 pub(crate) fn new(deadline: Instant, duration: Duration) -> Registration {
18 Registration {
19 entry: Entry::new(deadline, duration),
20 }
21 }
22
23 pub(crate) fn deadline(&self) -> Instant {
24 self.entry.time_ref().deadline
25 }
26
27 pub(crate) fn reset(&mut self, deadline: Instant) {
28 unsafe {
29 self.entry.time_mut().deadline = deadline;
30 }
31
32 Entry::reset(&mut self.entry);
33 }
34
35 pub(crate) fn is_elapsed(&self) -> bool {
36 self.entry.is_elapsed()
37 }
38
39 pub(crate) fn poll_elapsed(&self, cx: &mut task::Context<'_>) -> Poll<Result<(), Error>> {
40 self.entry.poll_elapsed(cx)
41 }
42}
43
44impl Drop for Registration {
45 fn drop(&mut self) {
46 Entry::cancel(&self.entry);
47 }
48}