[][src]Function juggle::spin_block_on

pub fn spin_block_on<F>(future: F) -> F::Output where
    F: Future

Utility for busy blocking on future.

Usefull for creating main loop on embedded systems. This function simply polls given future until it is ready. Waker used in polling is no-op, when future yields then it is polled again (with spin_loop_hint optimization).

Equivalent to block_on(future, || spin_loop_hint(), &noop_waker()).

Examples

use juggle::*;

let result = spin_block_on(async move {
    Yield::times(10).await;
    10
});
assert_eq!(result,10);
use juggle::*;

let wheel = Wheel::new();
wheel.handle().spawn(SpawnParams::default(),async move {
    loop{
        do_some_processing();
        yield_once!();
    }
});
wheel.handle().spawn(SpawnParams::default(),async move {
    // some other processing tasks
});

spin_block_on(wheel).unwrap();