binary_option_tools_core/utils/
time.rs

1use std::time::Duration;
2
3use crate::error::{BinaryOptionsResult, BinaryOptionsToolsError};
4use core::future::Future;
5
6pub async fn timeout<F, T>(duration: Duration, future: F, task: String) -> BinaryOptionsResult<T>
7where
8    F: Future<Output = BinaryOptionsResult<T>>,
9{
10    let res = tokio::select! {
11        _ = tokio::time::sleep(duration) => Err(BinaryOptionsToolsError::TimeoutError { task, duration }),
12        result = future => match result {
13            Ok(value) => Ok(value),
14            Err(err) => Err(err),
15        },
16    };
17    res
18}