async-std icon indicating copy to clipboard operation
async-std copied to clipboard

async-std's future timeout helper is too inflexible about errors

Open Fishrock123 opened this issue 3 years ago • 2 comments

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.

Fishrock123 avatar May 04 '21 00:05 Fishrock123

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")
}

jbr avatar May 04 '21 04:05 jbr

Completely avoids unnecessary error context loss due to error translations.

Fishrock123 avatar May 04 '21 06:05 Fishrock123