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.
22 lines
551 B
22 lines
551 B
extern crate trpl; // required for mdbook test
|
|
|
|
use std::time::Duration;
|
|
|
|
fn main() {
|
|
trpl::run(async {
|
|
// ANCHOR: here
|
|
let slow = async {
|
|
trpl::sleep(Duration::from_millis(100)).await;
|
|
"I finished!"
|
|
};
|
|
|
|
match timeout(slow, Duration::from_millis(10)).await {
|
|
Ok(message) => println!("Succeeded with '{message}'"),
|
|
Err(duration) => {
|
|
println!("Failed after {} seconds", duration.as_secs())
|
|
}
|
|
}
|
|
// ANCHOR_END: here
|
|
});
|
|
}
|