1use quilt_cell::Cell;
4use std::future::Future;
5use std::pin::Pin;
6use std::task::{Context, Poll};
7
8pub struct CellFuture {
9 cell: Cell,
10 ticks: u64,
11 done: bool,
12}
13
14impl CellFuture {
15 pub fn new(name: &str) -> Self {
16 Self {
17 cell: Cell::new(name),
18 ticks: 0,
19 done: false,
20 }
21 }
22}
23
24impl Future for CellFuture {
25 type Output = f64;
26 fn poll(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
27 if self.done { return Poll::Ready(0.0); }
28 self.ticks += 1;
29 if self.ticks >= 3 {
30 self.done = true;
31 Poll::Ready(self.ticks as f64)
32 } else {
33 Poll::Pending
34 }
35 }
36}
37
38pub fn after_ticks(name: &str, n: u64) -> CellFuture {
39 let mut f = CellFuture::new(name);
40 f.ticks = n;
41 f.done = n == 0;
42 f
43}
44
45#[cfg(test)]
46mod tests {
47 use super::*;
48 #[test]
49 fn test_future() {
50 let f = CellFuture::new("test");
51 assert!(!f.done);
52 }
53}