pub async fn with_timeout<Fut>(
    inner: Fut,
    duration: Duration
) -> Result<<Fut as Future>::Output, DeadlineExceeded> where
    Fut: Future
Expand description

Awaits inner, but returns DeadlineExceeded after duration time from now.

First moves inner to the heap, to make it Unpin. Use DeadlineFuture::new to avoid allocating on the heap.

Errors

Returns Err(DeadlineExceeded) if duration passes before inner completes.

Panics

Panics if start_timer_thread() has not been called. If you need to handle this error, use DeadlineFuture::new.