aboutsummaryrefslogtreecommitdiff
path: root/helix-event/src/cancel.rs
diff options
context:
space:
mode:
authorPascal Kuthe2023-11-30 23:03:26 +0000
committerBlaž Hrastnik2024-01-23 02:20:19 +0000
commit13ed4f6c4748019787d24c2b686d417b71604242 (patch)
tree8263b77ee05a22dfc85410345069efb3668b1877 /helix-event/src/cancel.rs
parent7d7ace551cd58f0b6d65af7a6dfa8f896d94724a (diff)
Add hook/event system
Diffstat (limited to 'helix-event/src/cancel.rs')
-rw-r--r--helix-event/src/cancel.rs19
1 files changed, 19 insertions, 0 deletions
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<T>(future: impl Future<Output = T>, cancel: CancelRx) -> Option<T> {
+ tokio::select! {
+ biased;
+ _ = cancel => {
+ None
+ }
+ res = future => {
+ Some(res)
+ }
+ }
+}