tuwunel_core/utils/future/
ext_ext.rs1use futures::{future, future::Select};
4
5pub trait ExtExt<T>
10where
11 Self: Future<Output = T> + Send,
12{
13 fn until<A, B, F>(self, f: F) -> Select<A, B>
18 where
19 Self: Sized,
20 F: FnOnce() -> B,
21 A: Future<Output = T> + From<Self> + Send + Unpin,
22 B: Future<Output = ()> + Send + Unpin;
23}
24
25impl<T, Fut> ExtExt<T> for Fut
26where
27 Fut: Future<Output = T> + Send,
28{
29 #[inline]
30 fn until<A, B, F>(self, f: F) -> Select<A, B>
31 where
32 Self: Sized,
33 F: FnOnce() -> B,
34 A: Future<Output = T> + From<Self> + Send + Unpin,
35 B: Future<Output = ()> + Send + Unpin,
36 {
37 future::select(self.into(), f())
38 }
39}