From 13ed4f6c4748019787d24c2b686d417b71604242 Mon Sep 17 00:00:00 2001 From: Pascal Kuthe Date: Fri, 1 Dec 2023 00:03:26 +0100 Subject: Add hook/event system --- helix-event/src/cancel.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 helix-event/src/cancel.rs (limited to 'helix-event/src/cancel.rs') diff --git a/helix-event/src/cancel.rs b/helix-event/src/cancel.rs new file mode 100644 index 00000000..f027be80 --- /dev/null +++ b/helix-event/src/cancel.rs @@ -0,0 +1,19 @@ +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(future: impl Future, cancel: CancelRx) -> Option { + tokio::select! { + biased; + _ = cancel => { + None + } + res = future => { + Some(res) + } + } +} -- cgit v1.2.3-70-g09d2