mirror of https://github.com/helix-editor/helix
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
433 B
Rust
20 lines
433 B
Rust
12 months ago
|
use std::future::Future;
|
||
|
|
||
|
pub use oneshot::channel as cancelation;
|
||
|
use tokio::sync::oneshot;
|
||
|
|
||
|
pub type CancelTx = oneshot::Sender<()>;
|
||
|
pub type CancelRx = oneshot::Receiver<()>;
|
||
|
|
||
|
pub async fn cancelable_future<T>(future: impl Future<Output = T>, cancel: CancelRx) -> Option<T> {
|
||
|
tokio::select! {
|
||
|
biased;
|
||
|
_ = cancel => {
|
||
|
None
|
||
|
}
|
||
|
res = future => {
|
||
|
Some(res)
|
||
|
}
|
||
|
}
|
||
|
}
|