hiasync 0.1.1

Supports only single-threaded asynchronous runtime
Documentation
mod task;
pub(crate) use task::*;

mod join;
pub use join::*;

mod waker;
pub use waker::*;

mod future;
pub use future::*;

mod runtime;
pub use runtime::*;

#[cfg(test)]
mod tests {
    use super::*;

    async fn foo(val: i32) -> i32 {
        sched_yield().await;
        val + 1
    }

    #[test]
    fn test0() {
        let mut rt = Runtime::new();
        let _ = rt.spawn(foo(0));
        let cnt = rt.sched();
        assert_eq!(cnt, 1);
        assert_eq!(rt.pending_count(), 0);
    }

    #[test]
    fn test1() {
        let mut rt = Runtime::new();
        let h1 = rt.spawn(foo(0));
        let h2 = rt.spawn(foo(1));
        let cnt = rt.sched();
        assert_eq!(h1.join(), Some(1));
        assert_eq!(h2.join(), Some(2));
        assert_eq!(cnt, 2);
        assert_eq!(rt.pending_count(), 0);
    }

    async fn bar(val: i32) -> i32 {
        *wait_event::<i32>(val as u64).await.unwrap()
    }

    #[test]
    fn test2() {
        let mut rt = Runtime::new();
        let h = rt.spawn(bar(100));
        let cnt = rt.sched();
        assert_eq!(cnt, 0);
        assert_eq!(h.is_finished(), false);
        assert_eq!(rt.pending_count(), 1);
        let cnt = rt.sched_events(&[Event::new(100, &200)]);
        assert_eq!(cnt, 1);
        assert_eq!(h.join(), Some(200));
        assert_eq!(rt.pending_count(), 0);
    }

    #[test]
    fn test3() {
        let mut rt = Runtime::new();
        let h = rt.spawn(bar(100));
        let cnt = rt.sched();
        assert_eq!(cnt, 0);
        assert_eq!(h.is_finished(), false);
        assert_eq!(rt.pending_count(), 1);
        rt.notify_events(&[Event::new(100, &300)]);
        let cnt = rt.sched();
        assert_eq!(cnt, 1);
        assert_eq!(h.join(), Some(300));
        assert_eq!(rt.pending_count(), 0);
    }

    async fn boo(val: i32) -> i32 {
        spawn(foo(val)).await.await
    }

    #[test]
    fn test4() {
        let mut rt = Runtime::new();
        let h = rt.spawn(boo(99));
        let cnt = rt.sched();
        assert_eq!(rt.pending_count(), 0);
        assert_eq!(cnt, 2);
        assert!(h.is_finished());
        assert_eq!(h.join(), Some(100));
    }
}