1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-10 08:09:06 -05:00
denoland-deno/cli/util/sync/async_flag.rs
2024-12-31 19:12:39 +00:00

20 lines
411 B
Rust

// Copyright 2018-2025 the Deno authors. 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()
}
}