diff options
Diffstat (limited to 'cli/util/sync/async_flag.rs')
-rw-r--r-- | cli/util/sync/async_flag.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/cli/util/sync/async_flag.rs b/cli/util/sync/async_flag.rs new file mode 100644 index 000000000..2bdff63c0 --- /dev/null +++ b/cli/util/sync/async_flag.rs @@ -0,0 +1,20 @@ +// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + +use tokio_util::sync::CancellationToken; + +#[derive(Debug, Default, Clone)] +pub struct AsyncFlag(CancellationToken); + +impl AsyncFlag { + pub fn raise(&self) { + self.0.cancel(); + } + + pub fn is_raised(&self) -> bool { + self.0.is_cancelled() + } + + pub fn wait_raised(&self) -> impl std::future::Future<Output = ()> + '_ { + self.0.cancelled() + } +} |