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