geph5-rt 0.3.4

tokio-based runtime helpers for geph5: cancel-on-drop tasks, immortal/respawn loops, a task reaper, a timeout combinator, and buffer-pooled reads
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//! A `.timeout()` future combinator backed by `tokio::time`, preserving the
//! `smol-timeout2` contract (returns `None` on timeout) so existing call sites
//! need only swap the import.

use std::future::Future;
use std::time::Duration;

/// Extension trait adding a `.timeout(duration)` combinator to any future.
///
/// Returns `Some(output)` if the future completes in time, or `None` if it
/// elapses — matching `smol_timeout2::TimeoutExt`.
pub trait TimeoutExt: Future + Sized {
    fn timeout(self, duration: Duration) -> impl Future<Output = Option<Self::Output>> {
        async move { tokio::time::timeout(duration, self).await.ok() }
    }
}

impl<F: Future> TimeoutExt for F {}