cliquenet/util.rs
1pub(crate) mod nonempty;
2
3use std::time::Duration;
4
5use crate::NetworkError;
6
7/// A variant of `timeout` that merges the timeout error into network error.
8pub(crate) async fn until<F, A, E>(t: Duration, fut: F) -> Result<A, NetworkError>
9where
10 F: Future<Output = Result<A, E>>,
11 E: Into<NetworkError>,
12{
13 match tokio::time::timeout(t, fut).await {
14 Ok(Ok(a)) => Ok(a),
15 Ok(Err(e)) => Err(e.into()),
16 Err(_) => Err(NetworkError::Timeout),
17 }
18}