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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#![cfg_attr(
feature = "std",
doc = r#"
```rust,no_run
#![forbid(unsafe_code)]
use pasts::prelude::*;
use async_std::task;
use std::{cell::RefCell, time::Duration};
async fn one(state: &RefCell<usize>) {
println!("Starting task one");
while *state.borrow() < 5 {
task::sleep(Duration::new(1, 0)).await;
let mut state = state.borrow_mut();
println!("One {}", *state);
*state += 1;
}
println!("Finish task one");
}
async fn two(state: &RefCell<usize>) {
println!("Starting task two");
loop {
task::sleep(Duration::new(2, 0)).await;
let mut state = state.borrow_mut();
println!("Two {}", *state);
*state += 1;
}
}
async fn example() {
let state = RefCell::new(0);
let mut task_one = one(&state);
let mut task_two = two(&state);
let mut tasks = [task_one.fut(), task_two.fut()];
tasks.select().await;
}
fn main() {
pasts::spawn(example);
}
```
"#
)]
#![cfg_attr(not(feature = "std"), no_std)]
#![doc(
html_logo_url = "https://libcala.github.io/logo.svg",
html_favicon_url = "https://libcala.github.io/icon.svg",
html_root_url = "https://docs.rs/pasts"
)]
#![deny(unsafe_code)]
#![warn(
anonymous_parameters,
missing_copy_implementations,
missing_debug_implementations,
missing_docs,
nonstandard_style,
rust_2018_idioms,
single_use_lifetimes,
trivial_casts,
trivial_numeric_casts,
unreachable_pub,
unused_extern_crates,
unused_qualifications,
variant_size_differences
)]
#[cfg(any(not(feature = "std"), target_arch = "wasm32"))]
extern crate alloc;
pub mod prelude {
pub use crate::DynFut;
pub use crate::Join;
pub use crate::{Select, SelectBoxed, SelectOptional};
}
mod dyn_future;
mod executor;
mod join;
mod select;
pub use dyn_future::DynFut;
pub use dyn_future::DynFuture;
pub use executor::{spawn, JoinHandle};
pub use join::Join;
pub use select::{Select, SelectBoxed, SelectOptional};