mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-05 02:20:10 +00:00
fdfed3d7db
Co-Authored-By: Max Brunsfeld <maxbrunsfeld@gmail.com>
20 lines
441 B
Rust
20 lines
441 B
Rust
use smol::future::FutureExt;
|
|
use std::{future::Future, time::Duration};
|
|
|
|
pub fn post_inc(value: &mut usize) -> usize {
|
|
let prev = *value;
|
|
*value += 1;
|
|
prev
|
|
}
|
|
|
|
pub async fn timeout<F, T>(timeout: Duration, f: F) -> Result<T, ()>
|
|
where
|
|
F: Future<Output = T>,
|
|
{
|
|
let timer = async {
|
|
smol::Timer::after(timeout).await;
|
|
Err(())
|
|
};
|
|
let future = async move { Ok(f.await) };
|
|
timer.race(future).await
|
|
}
|