1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use Future;
use Pin;
use spin_loop_hint;
use ;
use cratenoop_waker;
/// 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);
/// ```
/// ```
/// # #[macro_use]
/// use juggle::*;
/// # fn do_some_processing(){}
///
/// let wheel = Wheel::new();
/// # let id =
/// wheel.handle().spawn(SpawnParams::default(),async move {
/// loop{
/// do_some_processing();
/// yield_once!();
/// }
/// });
/// # let handle = wheel.handle().clone();
/// wheel.handle().spawn(SpawnParams::default(),async move {
/// // some other processing tasks
/// # Yield::times(10).await;
/// # handle.cancel(id.unwrap());
/// });
///
/// spin_block_on(wheel).unwrap();
/// ```
/// Utility for blocking on future with custom waker and pending action.
///
/// # Examples
/// ```
/// use juggle::*;
/// use juggle::utils::noop_waker;
///
/// let mut yield_count = 0;
/// let future = async move{
/// Yield::times(10).await;
/// 20
/// };
///
/// let result = block_on(future,||{ yield_count +=1; },&noop_waker());
/// assert_eq!(result,20);
/// assert_eq!(yield_count,10);
/// ```