fix(lsp): preserve notification order after init flag is raised (#28733)

This commit is contained in:
Nayeem Rahman 2025-04-03 23:54:09 +01:00 committed by GitHub
parent ec05282346
commit 7509fc26dd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,20 +1,28 @@
// Copyright 2018-2025 the Deno authors. MIT license.
use tokio_util::sync::CancellationToken;
use std::sync::Arc;
#[derive(Debug, Default, Clone)]
pub struct AsyncFlag(CancellationToken);
use tokio::sync::Semaphore;
#[derive(Debug, Clone)]
pub struct AsyncFlag(Arc<Semaphore>);
impl Default for AsyncFlag {
fn default() -> Self {
Self(Arc::new(Semaphore::new(0)))
}
}
impl AsyncFlag {
pub fn raise(&self) {
self.0.cancel();
self.0.close();
}
pub fn is_raised(&self) -> bool {
self.0.is_cancelled()
self.0.is_closed()
}
pub fn wait_raised(&self) -> impl std::future::Future<Output = ()> + '_ {
self.0.cancelled()
pub async fn wait_raised(&self) {
self.0.acquire().await.unwrap_err();
}
}