Run all asynchronous tasks at the same time
This commit is contained in:
parent
b5625b6c4c
commit
3be0c34179
1 changed files with 10 additions and 6 deletions
|
@ -2,16 +2,20 @@ use std::time::Duration;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
trpl::run(async {
|
trpl::run(async {
|
||||||
trpl::spawn_task(async {
|
let fut1 = async {
|
||||||
for i in 1..10 {
|
for i in 1..10 {
|
||||||
println!("hi number {i} from the first task!");
|
println!("hi number {i} from the first task!");
|
||||||
trpl::sleep(Duration::from_millis(500)).await;
|
trpl::sleep(Duration::from_millis(500)).await;
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
for i in 1..5 {
|
let fut2 = async {
|
||||||
println!("hi number {i} from the second task!");
|
for i in 1..5 {
|
||||||
trpl::sleep(Duration::from_millis(500)).await;
|
println!("hi number {i} from the second task!");
|
||||||
}
|
trpl::sleep(Duration::from_millis(500)).await;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
trpl::join(fut1, fut2).await;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue