summaryrefslogtreecommitdiff
path: root/cli/util/sync/async_flag.rs
blob: 2bdff63c040949eaadd88fc18a361c7233631191 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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()
  }
}