mirror of https://github.com/KaiserY/trpl-zh-cn
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
626 B
26 lines
626 B
extern crate trpl; // required for mdbook test
|
|
|
|
use std::time::Duration;
|
|
|
|
fn main() {
|
|
trpl::run(async {
|
|
// ANCHOR: join
|
|
let fut1 = async {
|
|
for i in 1..10 {
|
|
println!("hi number {i} from the first task!");
|
|
trpl::sleep(Duration::from_millis(500)).await;
|
|
}
|
|
};
|
|
|
|
let fut2 = async {
|
|
for i in 1..5 {
|
|
println!("hi number {i} from the second task!");
|
|
trpl::sleep(Duration::from_millis(500)).await;
|
|
}
|
|
};
|
|
|
|
trpl::join(fut1, fut2).await;
|
|
// ANCHOR_END: join
|
|
});
|
|
}
|