floop 0.2.1

A more convenient and less error prone replacement for loop `{ select! { .. }}`
Documentation
use std::{future::ready, time::Duration};

use floop::floop;
use smol::{Timer, block_on, future::poll_once};

#[test]
fn return_() {
    assert_eq!(block_on(return_32()), 32);
}

async fn return_32() -> i32 {
    let mut counter = 2;

    let result = floop!{
        unbiased
        return
        _ in Timer::after(Duration::from_millis(34)) => {
            counter *= 2;
        }
        _ in ready(()) => {
            break "foo";
        }
        _ in Timer::after(Duration::from_millis(41)) => {
            if counter == 32 {
                return counter;
            }
        }
    };

    let _: &str = result.1;
    match result.0 {}
}

#[test]
fn return_break() {
    let fut = async |i: i32| {
        floop!{
            biased
            return
            _ in Timer::after(Duration::from_millis(10)) => {
                if i == 5 {
                    return "return";
                } else {
                    break;
                }
            }
            () in ready(()) => {
                break "break";
            }
        }.1
    };

    block_on(async {
        assert_eq!(fut(5).await, "return");
        assert_eq!(fut(10).await, "break");
    })
}

#[test]
fn return_empty() {
    let fut = async {
        floop! {
            biased
            return
        }
    };

    assert_eq!(block_on(poll_once(fut)), Some(()));
}