Skip to content
Snippets Groups Projects
Commit 4f492058 authored by Egor Ivkov's avatar Egor Ivkov Committed by Егор Ивков
Browse files

feat: add sleep_async fn

parent 3ff98fcc
No related branches found
No related tags found
1 merge request!601refactor: improve join/update instance with cas
......@@ -3,6 +3,8 @@ use std::io::BufRead as _;
use std::io::BufReader;
use std::io::Write as _;
use std::os::unix::io::AsRawFd as _;
use tarantool::fiber;
use tarantool::fiber::r#async::timeout::IntoTimeout;
pub use Either::{Left, Right};
use crate::traft::error::Error;
......@@ -12,11 +14,18 @@ use std::time::{Duration, Instant};
const INFINITY: Duration = Duration::from_secs(30 * 365 * 24 * 60 * 60);
// TODO: move to tarantool_module when we have custom `Instance` there
pub fn instant_saturating_add(t: Instant, d: Duration) -> Instant {
t.checked_add(d)
.unwrap_or_else(|| t.checked_add(INFINITY).expect("that's too much, man"))
}
// TODO: move to tarantool_module
pub async fn sleep_async(time: Duration) {
let (_, rx) = fiber::r#async::oneshot::channel::<()>();
rx.timeout(time).await.unwrap_err();
}
////////////////////////////////////////////////////////////////////////////////
/// A generic enum that contains exactly one of two possible types. Equivalent
/// to `std::result::Result`, but is more intuitive in some cases.
......@@ -552,3 +561,12 @@ mod tests {
);
}
}
mod tarantool_tests {
use std::time::Duration;
#[::tarantool::test]
async fn sleep_wakes_up() {
super::sleep_async(Duration::from_millis(10)).await;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment