mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00
refactor(npm): improve locking around updating npm resolution (#24104)
Introduces a `SyncReadAsyncWriteLock` to make it harder to write to the npm resolution without first waiting async in a queue. For the npm resolution, reading synchronously is fine, but when updating, someone should wait async, clone the data, then write the data at the end back.
This commit is contained in:
parent
7ed90a20d0
commit
1b355d8a87
11 changed files with 417 additions and 225 deletions
20
cli/util/sync/async_flag.rs
Normal file
20
cli/util/sync/async_flag.rs
Normal file
|
@ -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()
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue