async-std
async-std copied to clipboard
async-std's future timeout helper is too inflexible about errors
The async_std::futures::timeout
helper would be much more useful if it was generic over Error
and took a callback closure to be called when a timeout is hit, so that one can construct /map to their own error type.
How would that be preferable to
#[async_std::main]
pub async fn main() -> Result<(), &'static str> {
async_std::future::timeout(std::time::Duration::from_secs(1), std::future::pending())
.await
.map_err(|_| "timed out")
}
Completely avoids unnecessary error context loss due to error translations.