40 lines
785 B
Rust
40 lines
785 B
Rust
use safe_executor::Runtime;
|
|
|
|
fn main() {
|
|
let runtime = Runtime::new();
|
|
|
|
let task1 = runtime.spawn(async move {
|
|
println!("task A");
|
|
"A"
|
|
});
|
|
|
|
let task2 = runtime.spawn(async move {
|
|
println!("task B");
|
|
"B"
|
|
});
|
|
|
|
let run2m = runtime.clone();
|
|
|
|
runtime.spawn(async move {
|
|
let res1 = task1.await;
|
|
let res2 = task2.await;
|
|
println!("task C, {:?}, {:?}", res1, res2);
|
|
|
|
let res3 = run2m
|
|
.spawn(async move {
|
|
println!("task D");
|
|
"D"
|
|
})
|
|
.await;
|
|
|
|
println!("task C, {:?}", res3);
|
|
});
|
|
|
|
while runtime.any_woken() {
|
|
println!("Ticking");
|
|
runtime.tick();
|
|
}
|
|
runtime.prune();
|
|
println!("Hewwo Mr Obama")
|
|
}
|