Timeouts
[![tokio-badge]][tokio] [![std-badge]][std]
Sometimes a task takes too long and you don't want to wait forever. A timeout puts a time limit
on a task. If it finishes in time you get the result, if it doesn't, it is cancelled and you get
an error back.
In this recipe, a network request is given 5 milliseconds to complete. If it finishes in time, the result is printed. If it runs over, the program reports a timeout.
use Duration;
use timeout;
async
async
Add tokio to Cargo.toml with the macros and time features enabled.
[dependencies]
tokio = { version = "*", features = ["macros", "time"] }
{{#include ../links.md}}