quilt-async 0.6.0

Quilt Async — async runtime for cells, futures and streams
Documentation
//! quilt-async — async runtime for cells. The cell awaits.

use quilt_cell::Cell;
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};

pub struct CellFuture {
    cell: Cell,
    ticks: u64,
    done: bool,
}

impl CellFuture {
    pub fn new(name: &str) -> Self {
        Self {
            cell: Cell::new(name),
            ticks: 0,
            done: false,
        }
    }
}

impl Future for CellFuture {
    type Output = f64;
    fn poll(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
        if self.done { return Poll::Ready(0.0); }
        self.ticks += 1;
        if self.ticks >= 3 {
            self.done = true;
            Poll::Ready(self.ticks as f64)
        } else {
            Poll::Pending
        }
    }
}

pub fn after_ticks(name: &str, n: u64) -> CellFuture {
    let mut f = CellFuture::new(name);
    f.ticks = n;
    f.done = n == 0;
    f
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_future() {
        let f = CellFuture::new("test");
        assert!(!f.done);
    }
}