mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 09:31:22 -05:00
chore: use parking_lot for synchronization primitives to align with tokio (#11289)
parking_lot is already transitively used in tokio via the "full" cargo feature
This commit is contained in:
parent
78ac19f51f
commit
7fc0e8ec8c
23 changed files with 109 additions and 117 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -637,6 +637,7 @@ dependencies = [
|
|||
"lazy_static",
|
||||
"libc",
|
||||
"log",
|
||||
"parking_lot",
|
||||
"pin-project",
|
||||
"rusty_v8",
|
||||
"serde",
|
||||
|
|
|
@ -17,6 +17,7 @@ use deno_core::error::uri_error;
|
|||
use deno_core::error::AnyError;
|
||||
use deno_core::futures;
|
||||
use deno_core::futures::future::FutureExt;
|
||||
use deno_core::parking_lot::Mutex;
|
||||
use deno_core::ModuleSpecifier;
|
||||
use deno_runtime::deno_fetch::reqwest;
|
||||
use deno_runtime::deno_web::BlobStore;
|
||||
|
@ -32,7 +33,6 @@ use std::io::Read;
|
|||
use std::path::PathBuf;
|
||||
use std::pin::Pin;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
|
||||
static DENO_AUTH_TOKENS: &str = "DENO_AUTH_TOKENS";
|
||||
pub const SUPPORTED_SCHEMES: [&str; 5] =
|
||||
|
@ -64,12 +64,12 @@ struct FileCache(Arc<Mutex<HashMap<ModuleSpecifier, File>>>);
|
|||
|
||||
impl FileCache {
|
||||
pub fn get(&self, specifier: &ModuleSpecifier) -> Option<File> {
|
||||
let cache = self.0.lock().unwrap();
|
||||
let cache = self.0.lock();
|
||||
cache.get(specifier).cloned()
|
||||
}
|
||||
|
||||
pub fn insert(&self, specifier: ModuleSpecifier, file: File) -> Option<File> {
|
||||
let mut cache = self.0.lock().unwrap();
|
||||
let mut cache = self.0.lock();
|
||||
cache.insert(specifier, file)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ use crate::colors;
|
|||
use deno_core::error::AnyError;
|
||||
use deno_core::futures::stream::{Stream, StreamExt};
|
||||
use deno_core::futures::Future;
|
||||
use deno_core::parking_lot::Mutex;
|
||||
use log::info;
|
||||
use notify::event::Event as NotifyEvent;
|
||||
use notify::event::EventKind;
|
||||
|
@ -17,7 +18,6 @@ use std::collections::HashSet;
|
|||
use std::path::PathBuf;
|
||||
use std::pin::Pin;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
use std::task::Context;
|
||||
use std::task::Poll;
|
||||
use std::time::Duration;
|
||||
|
@ -54,7 +54,7 @@ impl Stream for Debounce {
|
|||
self: Pin<&mut Self>,
|
||||
cx: &mut Context,
|
||||
) -> Poll<Option<Self::Item>> {
|
||||
let mut changed_paths = self.changed_paths.lock().unwrap();
|
||||
let mut changed_paths = self.changed_paths.lock();
|
||||
if changed_paths.len() > 0 {
|
||||
Poll::Ready(Some(changed_paths.drain().collect()))
|
||||
} else {
|
||||
|
@ -232,7 +232,7 @@ fn new_watcher(
|
|||
.paths
|
||||
.iter()
|
||||
.filter_map(|path| path.canonicalize().ok());
|
||||
let mut changed_paths = changed_paths.lock().unwrap();
|
||||
let mut changed_paths = changed_paths.lock();
|
||||
changed_paths.extend(paths);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ use crate::tokio_util::create_basic_runtime;
|
|||
|
||||
use deno_core::error::anyhow;
|
||||
use deno_core::error::AnyError;
|
||||
use deno_core::parking_lot::RwLock;
|
||||
use deno_core::serde::Deserialize;
|
||||
use deno_core::serde_json;
|
||||
use deno_core::serde_json::Value;
|
||||
|
@ -15,7 +16,6 @@ use lspower::lsp;
|
|||
use std::collections::BTreeMap;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use std::sync::RwLock;
|
||||
use std::thread;
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
|
@ -241,7 +241,7 @@ impl Config {
|
|||
Vec<(ModuleSpecifier, ModuleSpecifier)>,
|
||||
Vec<lsp::ConfigurationItem>,
|
||||
) = {
|
||||
let settings = settings_ref.read().unwrap();
|
||||
let settings = settings_ref.read();
|
||||
(
|
||||
settings
|
||||
.specifiers
|
||||
|
@ -259,7 +259,7 @@ impl Config {
|
|||
)
|
||||
};
|
||||
if let Ok(configs) = client.configuration(items).await {
|
||||
let mut settings = settings_ref.write().unwrap();
|
||||
let mut settings = settings_ref.write();
|
||||
for (i, value) in configs.into_iter().enumerate() {
|
||||
match serde_json::from_value::<SpecifierSettings>(value) {
|
||||
Ok(specifier_settings) => {
|
||||
|
@ -276,12 +276,7 @@ impl Config {
|
|||
}
|
||||
}
|
||||
Some(ConfigRequest::Specifier(specifier, uri)) => {
|
||||
if settings_ref
|
||||
.read()
|
||||
.unwrap()
|
||||
.specifiers
|
||||
.contains_key(&specifier)
|
||||
{
|
||||
if settings_ref.read().specifiers.contains_key(&specifier) {
|
||||
continue;
|
||||
}
|
||||
if let Ok(value) = client
|
||||
|
@ -297,7 +292,6 @@ impl Config {
|
|||
Ok(specifier_settings) => {
|
||||
settings_ref
|
||||
.write()
|
||||
.unwrap()
|
||||
.specifiers
|
||||
.insert(specifier, (uri, specifier_settings));
|
||||
}
|
||||
|
@ -327,14 +321,14 @@ impl Config {
|
|||
}
|
||||
|
||||
pub fn get_workspace_settings(&self) -> WorkspaceSettings {
|
||||
self.settings.read().unwrap().workspace.clone()
|
||||
self.settings.read().workspace.clone()
|
||||
}
|
||||
|
||||
/// Set the workspace settings directly, which occurs during initialization
|
||||
/// and when the client does not support workspace configuration requests
|
||||
pub fn set_workspace_settings(&self, value: Value) -> Result<(), AnyError> {
|
||||
let workspace_settings = serde_json::from_value(value)?;
|
||||
self.settings.write().unwrap().workspace = workspace_settings;
|
||||
self.settings.write().workspace = workspace_settings;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -345,14 +339,14 @@ impl Config {
|
|||
settings: self
|
||||
.settings
|
||||
.try_read()
|
||||
.map_err(|_| anyhow!("Error reading settings."))?
|
||||
.ok_or_else(|| anyhow!("Error reading settings."))?
|
||||
.clone(),
|
||||
workspace_folders: self.workspace_folders.clone(),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn specifier_enabled(&self, specifier: &ModuleSpecifier) -> bool {
|
||||
let settings = self.settings.read().unwrap();
|
||||
let settings = self.settings.read();
|
||||
settings
|
||||
.specifiers
|
||||
.get(specifier)
|
||||
|
@ -361,7 +355,7 @@ impl Config {
|
|||
}
|
||||
|
||||
pub fn specifier_code_lens_test(&self, specifier: &ModuleSpecifier) -> bool {
|
||||
let settings = self.settings.read().unwrap();
|
||||
let settings = self.settings.read();
|
||||
let value = settings
|
||||
.specifiers
|
||||
.get(specifier)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
use deno_core::parking_lot::Mutex;
|
||||
use deno_core::serde::Deserialize;
|
||||
use deno_core::serde::Serialize;
|
||||
use deno_core::serde_json::json;
|
||||
|
@ -9,7 +10,6 @@ use std::collections::HashMap;
|
|||
use std::collections::VecDeque;
|
||||
use std::fmt;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
|
||||
|
@ -93,7 +93,7 @@ impl Performance {
|
|||
#[cfg(test)]
|
||||
pub fn average(&self, name: &str) -> Option<(usize, Duration)> {
|
||||
let mut items = Vec::new();
|
||||
for measure in self.measures.lock().unwrap().iter() {
|
||||
for measure in self.measures.lock().iter() {
|
||||
if measure.name == name {
|
||||
items.push(measure.duration);
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ impl Performance {
|
|||
/// of each measurement.
|
||||
pub fn averages(&self) -> Vec<PerformanceAverage> {
|
||||
let mut averages: HashMap<String, Vec<Duration>> = HashMap::new();
|
||||
for measure in self.measures.lock().unwrap().iter() {
|
||||
for measure in self.measures.lock().iter() {
|
||||
averages
|
||||
.entry(measure.name.clone())
|
||||
.or_default()
|
||||
|
@ -140,7 +140,7 @@ impl Performance {
|
|||
maybe_args: Option<V>,
|
||||
) -> PerformanceMark {
|
||||
let name = name.as_ref();
|
||||
let mut counts = self.counts.lock().unwrap();
|
||||
let mut counts = self.counts.lock();
|
||||
let count = counts.entry(name.to_string()).or_insert(0);
|
||||
*count += 1;
|
||||
let msg = if let Some(args) = maybe_args {
|
||||
|
@ -179,7 +179,7 @@ impl Performance {
|
|||
})
|
||||
);
|
||||
let duration = measure.duration;
|
||||
let mut measures = self.measures.lock().unwrap();
|
||||
let mut measures = self.measures.lock();
|
||||
measures.push_front(measure);
|
||||
while measures.len() > self.max_size {
|
||||
measures.pop_back();
|
||||
|
@ -188,7 +188,7 @@ impl Performance {
|
|||
}
|
||||
|
||||
pub fn to_vec(&self) -> Vec<PerformanceMeasure> {
|
||||
let measures = self.measures.lock().unwrap();
|
||||
let measures = self.measures.lock();
|
||||
measures.iter().cloned().collect()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ use crate::text_encoding;
|
|||
|
||||
use deno_core::error::anyhow;
|
||||
use deno_core::error::AnyError;
|
||||
use deno_core::parking_lot::Mutex;
|
||||
use deno_core::serde_json;
|
||||
use deno_core::ModuleSpecifier;
|
||||
use deno_runtime::permissions::Permissions;
|
||||
|
@ -27,7 +28,6 @@ use std::fs;
|
|||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
use std::time::SystemTime;
|
||||
use tsc::NavigationTree;
|
||||
|
||||
|
@ -174,57 +174,57 @@ impl Sources {
|
|||
}
|
||||
|
||||
pub fn contains_key(&self, specifier: &ModuleSpecifier) -> bool {
|
||||
self.0.lock().unwrap().contains_key(specifier)
|
||||
self.0.lock().contains_key(specifier)
|
||||
}
|
||||
|
||||
pub fn get_line_index(
|
||||
&self,
|
||||
specifier: &ModuleSpecifier,
|
||||
) -> Option<LineIndex> {
|
||||
self.0.lock().unwrap().get_line_index(specifier)
|
||||
self.0.lock().get_line_index(specifier)
|
||||
}
|
||||
|
||||
pub fn get_maybe_types(
|
||||
&self,
|
||||
specifier: &ModuleSpecifier,
|
||||
) -> Option<analysis::ResolvedDependency> {
|
||||
self.0.lock().unwrap().get_maybe_types(specifier)
|
||||
self.0.lock().get_maybe_types(specifier)
|
||||
}
|
||||
|
||||
pub fn get_maybe_warning(
|
||||
&self,
|
||||
specifier: &ModuleSpecifier,
|
||||
) -> Option<String> {
|
||||
self.0.lock().unwrap().get_maybe_warning(specifier)
|
||||
self.0.lock().get_maybe_warning(specifier)
|
||||
}
|
||||
|
||||
pub fn get_media_type(
|
||||
&self,
|
||||
specifier: &ModuleSpecifier,
|
||||
) -> Option<MediaType> {
|
||||
self.0.lock().unwrap().get_media_type(specifier)
|
||||
self.0.lock().get_media_type(specifier)
|
||||
}
|
||||
|
||||
pub fn get_navigation_tree(
|
||||
&self,
|
||||
specifier: &ModuleSpecifier,
|
||||
) -> Option<tsc::NavigationTree> {
|
||||
self.0.lock().unwrap().get_navigation_tree(specifier)
|
||||
self.0.lock().get_navigation_tree(specifier)
|
||||
}
|
||||
|
||||
pub fn get_script_version(
|
||||
&self,
|
||||
specifier: &ModuleSpecifier,
|
||||
) -> Option<String> {
|
||||
self.0.lock().unwrap().get_script_version(specifier)
|
||||
self.0.lock().get_script_version(specifier)
|
||||
}
|
||||
|
||||
pub fn get_source(&self, specifier: &ModuleSpecifier) -> Option<String> {
|
||||
self.0.lock().unwrap().get_source(specifier)
|
||||
self.0.lock().get_source(specifier)
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.0.lock().unwrap().metadata.len()
|
||||
self.0.lock().metadata.len()
|
||||
}
|
||||
|
||||
pub fn resolve_import(
|
||||
|
@ -232,11 +232,11 @@ impl Sources {
|
|||
specifier: &str,
|
||||
referrer: &ModuleSpecifier,
|
||||
) -> Option<(ModuleSpecifier, MediaType)> {
|
||||
self.0.lock().unwrap().resolve_import(specifier, referrer)
|
||||
self.0.lock().resolve_import(specifier, referrer)
|
||||
}
|
||||
|
||||
pub fn specifiers(&self) -> Vec<ModuleSpecifier> {
|
||||
self.0.lock().unwrap().metadata.keys().cloned().collect()
|
||||
self.0.lock().metadata.keys().cloned().collect()
|
||||
}
|
||||
|
||||
pub fn set_navigation_tree(
|
||||
|
@ -247,7 +247,6 @@ impl Sources {
|
|||
self
|
||||
.0
|
||||
.lock()
|
||||
.unwrap()
|
||||
.set_navigation_tree(specifier, navigation_tree)
|
||||
}
|
||||
}
|
||||
|
@ -660,7 +659,7 @@ mod tests {
|
|||
let (sources, _) = setup();
|
||||
let specifier =
|
||||
resolve_url("foo://a/b/c.ts").expect("could not create specifier");
|
||||
let sources = sources.0.lock().unwrap();
|
||||
let sources = sources.0.lock();
|
||||
let mut redirects = sources.redirects.clone();
|
||||
let http_cache = sources.http_cache.clone();
|
||||
let actual = resolve_specifier(&specifier, &mut redirects, &http_cache);
|
||||
|
|
|
@ -56,6 +56,7 @@ use deno_core::error::AnyError;
|
|||
use deno_core::futures::future::FutureExt;
|
||||
use deno_core::futures::Future;
|
||||
use deno_core::located_script_name;
|
||||
use deno_core::parking_lot::Mutex;
|
||||
use deno_core::resolve_url_or_path;
|
||||
use deno_core::serde_json;
|
||||
use deno_core::serde_json::json;
|
||||
|
@ -78,7 +79,6 @@ use std::path::PathBuf;
|
|||
use std::pin::Pin;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
use tools::test_runner;
|
||||
|
||||
fn create_web_worker_callback(
|
||||
|
|
|
@ -32,6 +32,7 @@ use deno_core::error::AnyError;
|
|||
use deno_core::error::Context;
|
||||
use deno_core::futures::stream::FuturesUnordered;
|
||||
use deno_core::futures::stream::StreamExt;
|
||||
use deno_core::parking_lot::Mutex;
|
||||
use deno_core::resolve_import;
|
||||
use deno_core::resolve_url_or_path;
|
||||
use deno_core::serde::Deserialize;
|
||||
|
@ -55,7 +56,6 @@ use std::path::PathBuf;
|
|||
use std::rc::Rc;
|
||||
use std::result;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
use std::time::Instant;
|
||||
use swc_common::comments::Comment;
|
||||
use swc_common::BytePos;
|
||||
|
@ -459,7 +459,7 @@ impl Module {
|
|||
) -> Result<ModuleSpecifier, AnyError> {
|
||||
let maybe_resolve = if let Some(import_map) = self.maybe_import_map.clone()
|
||||
{
|
||||
let import_map = import_map.lock().unwrap();
|
||||
let import_map = import_map.lock();
|
||||
Some(import_map.resolve(specifier, self.specifier.as_str())?)
|
||||
} else {
|
||||
None
|
||||
|
@ -911,7 +911,7 @@ impl Graph {
|
|||
root_names,
|
||||
})?;
|
||||
|
||||
let mut graph = graph.lock().unwrap();
|
||||
let mut graph = graph.lock();
|
||||
graph.maybe_tsbuildinfo = response.maybe_tsbuildinfo;
|
||||
// Only process changes to the graph if there are no diagnostics and there
|
||||
// were files emitted.
|
||||
|
@ -1047,7 +1047,7 @@ impl Graph {
|
|||
root_names,
|
||||
})?;
|
||||
|
||||
let graph = graph.lock().unwrap();
|
||||
let graph = graph.lock();
|
||||
match options.bundle_type {
|
||||
BundleType::Module | BundleType::Classic => {
|
||||
assert!(
|
||||
|
@ -1250,7 +1250,7 @@ impl Graph {
|
|||
/// Update the handler with any modules that are marked as _dirty_ and update
|
||||
/// any build info if present.
|
||||
fn flush(&mut self) -> Result<(), AnyError> {
|
||||
let mut handler = self.handler.lock().unwrap();
|
||||
let mut handler = self.handler.lock();
|
||||
for (_, module_slot) in self.modules.iter_mut() {
|
||||
if let ModuleSlot::Module(module) = module_slot {
|
||||
if module.is_dirty {
|
||||
|
@ -1541,7 +1541,7 @@ impl Graph {
|
|||
/// error if any of the resources do not match their lock status.
|
||||
pub fn lock(&self) {
|
||||
if let Some(lf) = self.maybe_lockfile.as_ref() {
|
||||
let mut lockfile = lf.lock().unwrap();
|
||||
let mut lockfile = lf.lock();
|
||||
for (ms, module_slot) in self.modules.iter() {
|
||||
if let ModuleSlot::Module(module) = module_slot {
|
||||
let specifier = module.specifier.to_string();
|
||||
|
@ -1865,7 +1865,7 @@ impl GraphBuilder {
|
|||
self.graph.roots.push(specifier.clone());
|
||||
self.graph.roots_dynamic = self.graph.roots_dynamic && is_dynamic;
|
||||
if self.graph.maybe_tsbuildinfo.is_none() {
|
||||
let handler = self.graph.handler.lock().unwrap();
|
||||
let handler = self.graph.handler.lock();
|
||||
self.graph.maybe_tsbuildinfo = handler.get_tsbuildinfo(specifier)?;
|
||||
}
|
||||
}
|
||||
|
@ -1933,7 +1933,7 @@ impl GraphBuilder {
|
|||
.graph
|
||||
.modules
|
||||
.insert(specifier.clone(), ModuleSlot::Pending);
|
||||
let mut handler = self.graph.handler.lock().unwrap();
|
||||
let mut handler = self.graph.handler.lock();
|
||||
let future =
|
||||
handler.fetch(specifier.clone(), maybe_referrer.clone(), is_dynamic);
|
||||
self.pending.push(future);
|
||||
|
@ -2003,7 +2003,7 @@ impl GraphBuilder {
|
|||
let has_types = module.maybe_types.is_some();
|
||||
module.parse()?;
|
||||
if self.maybe_import_map.is_none() {
|
||||
let mut handler = self.graph.handler.lock().unwrap();
|
||||
let mut handler = self.graph.handler.lock();
|
||||
handler.set_deps(&specifier, module.dependencies.clone())?;
|
||||
if !has_types {
|
||||
if let Some((types, _)) = module.maybe_types.clone() {
|
||||
|
@ -2070,10 +2070,10 @@ pub mod tests {
|
|||
|
||||
use crate::specifier_handler::MemoryHandler;
|
||||
use deno_core::futures::future;
|
||||
use deno_core::parking_lot::Mutex;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Mutex;
|
||||
|
||||
macro_rules! map (
|
||||
{ $($key:expr => $value:expr),+ } => {
|
||||
|
@ -2360,7 +2360,7 @@ pub mod tests {
|
|||
assert!(result_info.maybe_ignored_options.is_none());
|
||||
assert_eq!(result_info.stats.0.len(), 12);
|
||||
assert!(result_info.diagnostics.is_empty());
|
||||
let h = handler.lock().unwrap();
|
||||
let h = handler.lock();
|
||||
assert_eq!(h.cache_calls.len(), 2);
|
||||
assert_eq!(h.tsbuildinfo_calls.len(), 1);
|
||||
}
|
||||
|
@ -2401,7 +2401,7 @@ pub mod tests {
|
|||
assert!(result_info.maybe_ignored_options.is_none());
|
||||
assert_eq!(result_info.stats.0.len(), 12);
|
||||
assert!(!result_info.diagnostics.is_empty());
|
||||
let h = handler.lock().unwrap();
|
||||
let h = handler.lock();
|
||||
// we shouldn't cache any files or write out tsbuildinfo if there are
|
||||
// diagnostic errors
|
||||
assert_eq!(h.cache_calls.len(), 0);
|
||||
|
@ -2426,7 +2426,7 @@ pub mod tests {
|
|||
assert!(result_info.maybe_ignored_options.is_none());
|
||||
assert_eq!(result_info.stats.0.len(), 12);
|
||||
assert!(result_info.diagnostics.is_empty());
|
||||
let h = handler.lock().unwrap();
|
||||
let h = handler.lock();
|
||||
assert_eq!(h.cache_calls.len(), 0);
|
||||
assert_eq!(h.tsbuildinfo_calls.len(), 1);
|
||||
}
|
||||
|
@ -2448,7 +2448,7 @@ pub mod tests {
|
|||
.expect("should have checked");
|
||||
assert!(result_info.maybe_ignored_options.is_none());
|
||||
assert!(result_info.diagnostics.is_empty());
|
||||
let h = handler.lock().unwrap();
|
||||
let h = handler.lock();
|
||||
assert_eq!(h.cache_calls.len(), 1);
|
||||
assert_eq!(h.tsbuildinfo_calls.len(), 1);
|
||||
}
|
||||
|
@ -2491,7 +2491,7 @@ pub mod tests {
|
|||
assert!(result_info.maybe_ignored_options.is_none());
|
||||
assert!(result_info.diagnostics.is_empty());
|
||||
let (ver0, ver1) = {
|
||||
let h = handler.lock().unwrap();
|
||||
let h = handler.lock();
|
||||
assert_eq!(h.version_calls.len(), 2);
|
||||
(h.version_calls[0].1.clone(), h.version_calls[1].1.clone())
|
||||
};
|
||||
|
@ -2512,7 +2512,7 @@ pub mod tests {
|
|||
.expect("should have checked");
|
||||
assert!(result_info.maybe_ignored_options.is_none());
|
||||
assert!(result_info.diagnostics.is_empty());
|
||||
let h = handler.lock().unwrap();
|
||||
let h = handler.lock();
|
||||
assert_eq!(h.version_calls.len(), 2);
|
||||
assert!(h.version_calls[0].1 == ver0 || h.version_calls[0].1 == ver1);
|
||||
assert!(h.version_calls[1].1 == ver0 || h.version_calls[1].1 == ver1);
|
||||
|
@ -2681,7 +2681,7 @@ pub mod tests {
|
|||
let result_info = graph.transpile(TranspileOptions::default()).unwrap();
|
||||
assert_eq!(result_info.stats.0.len(), 3);
|
||||
assert_eq!(result_info.maybe_ignored_options, None);
|
||||
let h = handler.lock().unwrap();
|
||||
let h = handler.lock();
|
||||
assert_eq!(h.cache_calls.len(), 2);
|
||||
match &h.cache_calls[0].1 {
|
||||
Emit::Cli((code, maybe_map)) => {
|
||||
|
@ -2743,7 +2743,7 @@ pub mod tests {
|
|||
vec!["target".to_string()],
|
||||
"the 'target' options should have been ignored"
|
||||
);
|
||||
let h = handler.lock().unwrap();
|
||||
let h = handler.lock();
|
||||
assert_eq!(h.cache_calls.len(), 1, "only one file should be emitted");
|
||||
// FIXME(bartlomieju): had to add space in `<div>`, probably a quirk in swc_ecma_codegen
|
||||
match &h.cache_calls[0].1 {
|
||||
|
|
|
@ -13,6 +13,7 @@ use deno_core::error::generic_error;
|
|||
use deno_core::error::type_error;
|
||||
use deno_core::error::AnyError;
|
||||
use deno_core::error::Context;
|
||||
use deno_core::parking_lot::Mutex;
|
||||
use deno_core::resolve_url_or_path;
|
||||
use deno_core::serde_json;
|
||||
use deno_core::serde_json::json;
|
||||
|
@ -24,7 +25,6 @@ use std::cell::RefCell;
|
|||
use std::collections::HashMap;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
|
||||
pub fn init(rt: &mut deno_core::JsRuntime) {
|
||||
super::reg_async(rt, "op_emit", op_emit);
|
||||
|
|
|
@ -25,6 +25,7 @@ use deno_core::error::anyhow;
|
|||
use deno_core::error::get_custom_error_class;
|
||||
use deno_core::error::AnyError;
|
||||
use deno_core::error::Context;
|
||||
use deno_core::parking_lot::Mutex;
|
||||
use deno_core::resolve_url;
|
||||
use deno_core::url::Url;
|
||||
use deno_core::ModuleSource;
|
||||
|
@ -36,7 +37,6 @@ use std::collections::HashSet;
|
|||
use std::env;
|
||||
use std::fs::read;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
|
||||
/// This structure represents state of single "deno" program.
|
||||
///
|
||||
|
@ -184,7 +184,7 @@ impl ProgramState {
|
|||
let debug = self.flags.log_level == Some(log::Level::Debug);
|
||||
let maybe_config_file = self.maybe_config_file.clone();
|
||||
let reload_exclusions = {
|
||||
let modules = self.modules.lock().unwrap();
|
||||
let modules = self.modules.lock();
|
||||
modules.keys().cloned().collect::<HashSet<_>>()
|
||||
};
|
||||
|
||||
|
@ -220,11 +220,11 @@ impl ProgramState {
|
|||
result_info.loadable_modules
|
||||
};
|
||||
|
||||
let mut loadable_modules = self.modules.lock().unwrap();
|
||||
let mut loadable_modules = self.modules.lock();
|
||||
loadable_modules.extend(result_modules);
|
||||
|
||||
if let Some(ref lockfile) = self.lockfile {
|
||||
let g = lockfile.lock().unwrap();
|
||||
let g = lockfile.lock();
|
||||
g.write()?;
|
||||
}
|
||||
|
||||
|
@ -258,7 +258,7 @@ impl ProgramState {
|
|||
let debug = self.flags.log_level == Some(log::Level::Debug);
|
||||
let maybe_config_file = self.maybe_config_file.clone();
|
||||
let reload_exclusions = {
|
||||
let modules = self.modules.lock().unwrap();
|
||||
let modules = self.modules.lock();
|
||||
modules.keys().cloned().collect::<HashSet<_>>()
|
||||
};
|
||||
|
||||
|
@ -294,11 +294,11 @@ impl ProgramState {
|
|||
result_info.loadable_modules
|
||||
};
|
||||
|
||||
let mut loadable_modules = self.modules.lock().unwrap();
|
||||
let mut loadable_modules = self.modules.lock();
|
||||
loadable_modules.extend(result_modules);
|
||||
|
||||
if let Some(ref lockfile) = self.lockfile {
|
||||
let g = lockfile.lock().unwrap();
|
||||
let g = lockfile.lock();
|
||||
g.write()?;
|
||||
}
|
||||
|
||||
|
@ -310,7 +310,7 @@ impl ProgramState {
|
|||
specifier: ModuleSpecifier,
|
||||
maybe_referrer: Option<ModuleSpecifier>,
|
||||
) -> Result<ModuleSource, AnyError> {
|
||||
let modules = self.modules.lock().unwrap();
|
||||
let modules = self.modules.lock();
|
||||
modules
|
||||
.get(&specifier)
|
||||
.map(|r| match r {
|
||||
|
|
|
@ -14,6 +14,7 @@ use crate::write_to_stdout_ignore_sigpipe;
|
|||
use deno_core::error::AnyError;
|
||||
use deno_core::futures::future::FutureExt;
|
||||
use deno_core::futures::Future;
|
||||
use deno_core::parking_lot::Mutex;
|
||||
use deno_core::resolve_url_or_path;
|
||||
use deno_doc as doc;
|
||||
use deno_doc::parser::DocFileLoader;
|
||||
|
@ -21,7 +22,6 @@ use deno_runtime::permissions::Permissions;
|
|||
use std::path::PathBuf;
|
||||
use std::pin::Pin;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
use swc_ecmascript::parser::Syntax;
|
||||
|
||||
type DocResult = Result<(Syntax, String), doc::DocError>;
|
||||
|
|
|
@ -317,8 +317,8 @@ fn is_in_path(dir: &Path) -> bool {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use deno_core::parking_lot::Mutex;
|
||||
use std::process::Command;
|
||||
use std::sync::Mutex;
|
||||
use tempfile::TempDir;
|
||||
use test_util::tests_path;
|
||||
|
||||
|
@ -401,7 +401,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn install_basic() {
|
||||
let _guard = ENV_LOCK.lock().ok();
|
||||
let _guard = ENV_LOCK.lock();
|
||||
let temp_dir = TempDir::new().expect("tempdir fail");
|
||||
let temp_dir_str = temp_dir.path().to_string_lossy().to_string();
|
||||
// NOTE: this test overrides environmental variables
|
||||
|
@ -591,7 +591,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn install_custom_dir_env_var() {
|
||||
let _guard = ENV_LOCK.lock().ok();
|
||||
let _guard = ENV_LOCK.lock();
|
||||
let temp_dir = TempDir::new().expect("tempdir fail");
|
||||
let bin_dir = temp_dir.path().join("bin");
|
||||
std::fs::create_dir(&bin_dir).unwrap();
|
||||
|
|
|
@ -9,6 +9,7 @@ use crate::media_type::MediaType;
|
|||
use crate::program_state::ProgramState;
|
||||
use deno_core::error::AnyError;
|
||||
use deno_core::futures::FutureExt;
|
||||
use deno_core::parking_lot::Mutex;
|
||||
use deno_core::serde_json::json;
|
||||
use deno_core::serde_json::Value;
|
||||
use deno_core::LocalInspectorSession;
|
||||
|
@ -28,7 +29,6 @@ use std::borrow::Cow;
|
|||
use std::cell::RefCell;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
use swc_ecmascript::parser::token::{Token, Word};
|
||||
use tokio::sync::mpsc::channel;
|
||||
use tokio::sync::mpsc::unbounded_channel;
|
||||
|
@ -324,21 +324,17 @@ impl ReplEditor {
|
|||
}
|
||||
|
||||
pub fn readline(&self) -> Result<String, ReadlineError> {
|
||||
self.inner.lock().unwrap().readline("> ")
|
||||
self.inner.lock().readline("> ")
|
||||
}
|
||||
|
||||
pub fn add_history_entry(&self, entry: String) {
|
||||
self.inner.lock().unwrap().add_history_entry(entry);
|
||||
self.inner.lock().add_history_entry(entry);
|
||||
}
|
||||
|
||||
pub fn save_history(&self) -> Result<(), AnyError> {
|
||||
std::fs::create_dir_all(self.history_file_path.parent().unwrap())?;
|
||||
|
||||
self
|
||||
.inner
|
||||
.lock()
|
||||
.unwrap()
|
||||
.save_history(&self.history_file_path)?;
|
||||
self.inner.lock().save_history(&self.history_file_path)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
10
cli/tsc.rs
10
cli/tsc.rs
|
@ -12,6 +12,7 @@ use deno_core::error::AnyError;
|
|||
use deno_core::error::Context;
|
||||
use deno_core::located_script_name;
|
||||
use deno_core::op_sync;
|
||||
use deno_core::parking_lot::Mutex;
|
||||
use deno_core::resolve_url_or_path;
|
||||
use deno_core::serde::de;
|
||||
use deno_core::serde::Deserialize;
|
||||
|
@ -27,7 +28,6 @@ use deno_core::Snapshot;
|
|||
use std::collections::HashMap;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
|
||||
// Declaration files
|
||||
|
||||
|
@ -336,7 +336,7 @@ fn op_exists(state: &mut State, args: ExistsArgs) -> Result<bool, AnyError> {
|
|||
if specifier.scheme() == "asset" || specifier.scheme() == "data" {
|
||||
Ok(true)
|
||||
} else {
|
||||
let graph = state.graph.lock().unwrap();
|
||||
let graph = state.graph.lock();
|
||||
Ok(graph.contains(&specifier))
|
||||
}
|
||||
} else {
|
||||
|
@ -372,7 +372,7 @@ fn op_load(state: &mut State, args: Value) -> Result<Value, AnyError> {
|
|||
media_type = MediaType::from(&v.specifier);
|
||||
maybe_source
|
||||
} else {
|
||||
let graph = state.graph.lock().unwrap();
|
||||
let graph = state.graph.lock();
|
||||
let specifier = if let Some(data_specifier) =
|
||||
state.data_url_map.get(&v.specifier)
|
||||
{
|
||||
|
@ -427,7 +427,7 @@ fn op_resolve(state: &mut State, args: Value) -> Result<Value, AnyError> {
|
|||
MediaType::from(specifier).as_ts_extension().to_string(),
|
||||
));
|
||||
} else {
|
||||
let graph = state.graph.lock().unwrap();
|
||||
let graph = state.graph.lock();
|
||||
match graph.resolve(specifier, &referrer, true) {
|
||||
Ok(resolved_specifier) => {
|
||||
let media_type = if let Some(media_type) =
|
||||
|
@ -593,9 +593,9 @@ mod tests {
|
|||
use crate::diagnostics::DiagnosticCategory;
|
||||
use crate::module_graph::tests::MockSpecifierHandler;
|
||||
use crate::module_graph::GraphBuilder;
|
||||
use deno_core::parking_lot::Mutex;
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Mutex;
|
||||
|
||||
async fn setup(
|
||||
maybe_specifier: Option<ModuleSpecifier>,
|
||||
|
|
|
@ -19,6 +19,7 @@ indexmap = "1.6.2"
|
|||
lazy_static = "1.4.0"
|
||||
libc = "0.2.93"
|
||||
log = "0.4.14"
|
||||
parking_lot = "0.11.1"
|
||||
pin-project = "1.0.6"
|
||||
rusty_v8 = "0.25.0"
|
||||
serde = { version = "1.0.125", features = ["derive"] }
|
||||
|
|
|
@ -23,6 +23,7 @@ use crate::serde_json;
|
|||
use crate::serde_json::json;
|
||||
use crate::serde_json::Value;
|
||||
use crate::v8;
|
||||
use parking_lot::Mutex;
|
||||
use std::cell::BorrowMutError;
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
|
@ -35,7 +36,6 @@ use std::ptr;
|
|||
use std::ptr::NonNull;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
use std::thread;
|
||||
|
||||
/// If first argument is `None` then it's a notification, otherwise
|
||||
|
@ -452,7 +452,7 @@ impl InspectorWaker {
|
|||
where
|
||||
F: FnOnce(&mut InspectorWakerInner) -> R,
|
||||
{
|
||||
let mut g = self.0.lock().unwrap();
|
||||
let mut g = self.0.lock();
|
||||
update_fn(&mut g)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ mod runtime;
|
|||
|
||||
// Re-exports
|
||||
pub use futures;
|
||||
pub use parking_lot;
|
||||
pub use rusty_v8 as v8;
|
||||
pub use serde;
|
||||
pub use serde_json;
|
||||
|
|
|
@ -719,6 +719,7 @@ mod tests {
|
|||
use crate::OpPayload;
|
||||
use crate::RuntimeOptions;
|
||||
use futures::future::FutureExt;
|
||||
use parking_lot::Mutex;
|
||||
use std::error::Error;
|
||||
use std::fmt;
|
||||
use std::future::Future;
|
||||
|
@ -726,7 +727,6 @@ mod tests {
|
|||
use std::path::PathBuf;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
|
||||
// TODO(ry) Sadly FuturesUnordered requires the current task to be set. So
|
||||
// even though we are only using poll() in these tests and not Tokio, we must
|
||||
|
@ -856,7 +856,7 @@ mod tests {
|
|||
_maybe_referrer: Option<ModuleSpecifier>,
|
||||
_is_dyn_import: bool,
|
||||
) -> Pin<Box<ModuleSourceFuture>> {
|
||||
let mut loads = self.loads.lock().unwrap();
|
||||
let mut loads = self.loads.lock();
|
||||
loads.push(module_specifier.to_string());
|
||||
let url = module_specifier.to_string();
|
||||
DelayedSourceCodeFuture { url, counter: 0 }.boxed()
|
||||
|
@ -908,7 +908,7 @@ mod tests {
|
|||
|
||||
runtime.mod_evaluate(a_id);
|
||||
futures::executor::block_on(runtime.run_event_loop(false)).unwrap();
|
||||
let l = loads.lock().unwrap();
|
||||
let l = loads.lock();
|
||||
assert_eq!(
|
||||
l.to_vec(),
|
||||
vec![
|
||||
|
@ -1369,7 +1369,7 @@ mod tests {
|
|||
runtime.mod_evaluate(circular1_id);
|
||||
runtime.run_event_loop(false).await.unwrap();
|
||||
|
||||
let l = loads.lock().unwrap();
|
||||
let l = loads.lock();
|
||||
assert_eq!(
|
||||
l.to_vec(),
|
||||
vec![
|
||||
|
@ -1441,7 +1441,7 @@ mod tests {
|
|||
let redirect1_id = result.unwrap();
|
||||
runtime.mod_evaluate(redirect1_id);
|
||||
runtime.run_event_loop(false).await.unwrap();
|
||||
let l = loads.lock().unwrap();
|
||||
let l = loads.lock();
|
||||
assert_eq!(
|
||||
l.to_vec(),
|
||||
vec![
|
||||
|
@ -1517,7 +1517,7 @@ mod tests {
|
|||
for _ in 0..10 {
|
||||
let result = recursive_load.poll_unpin(&mut cx);
|
||||
assert!(result.is_pending());
|
||||
let l = loads.lock().unwrap();
|
||||
let l = loads.lock();
|
||||
assert_eq!(
|
||||
l.to_vec(),
|
||||
vec![
|
||||
|
@ -1591,7 +1591,7 @@ mod tests {
|
|||
runtime.mod_evaluate(main_id);
|
||||
futures::executor::block_on(runtime.run_event_loop(false)).unwrap();
|
||||
|
||||
let l = loads.lock().unwrap();
|
||||
let l = loads.lock();
|
||||
assert_eq!(
|
||||
l.to_vec(),
|
||||
vec!["file:///b.js", "file:///c.js", "file:///d.js"]
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
use crate::BroadcastChannel;
|
||||
use async_trait::async_trait;
|
||||
use deno_core::error::AnyError;
|
||||
use deno_core::parking_lot::Mutex;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
use tokio::sync::broadcast;
|
||||
use tokio::sync::mpsc;
|
||||
use uuid::Uuid;
|
||||
|
@ -41,7 +41,7 @@ impl BroadcastChannel for InMemoryBroadcastChannel {
|
|||
|
||||
fn subscribe(&self) -> Result<Self::Resource, AnyError> {
|
||||
let (cancel_tx, cancel_rx) = mpsc::unbounded_channel();
|
||||
let broadcast_rx = self.0.lock().unwrap().subscribe();
|
||||
let broadcast_rx = self.0.lock().subscribe();
|
||||
let rx = tokio::sync::Mutex::new((broadcast_rx, cancel_rx));
|
||||
let uuid = Uuid::new_v4();
|
||||
Ok(Self::Resource {
|
||||
|
@ -64,7 +64,7 @@ impl BroadcastChannel for InMemoryBroadcastChannel {
|
|||
let name = Arc::new(name);
|
||||
let data = Arc::new(data);
|
||||
let uuid = resource.uuid;
|
||||
self.0.lock().unwrap().send(Message { name, data, uuid })?;
|
||||
self.0.lock().send(Message { name, data, uuid })?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ use deno_core::futures::task::RawWakerVTable;
|
|||
use deno_core::futures::task::Waker;
|
||||
use deno_core::op_async;
|
||||
use deno_core::op_sync;
|
||||
use deno_core::parking_lot::Mutex;
|
||||
use deno_core::AsyncRefCell;
|
||||
use deno_core::CancelHandle;
|
||||
use deno_core::CancelTryFuture;
|
||||
|
@ -66,7 +67,6 @@ use std::path::Path;
|
|||
use std::pin::Pin;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
use std::sync::Weak;
|
||||
use tokio::io::AsyncRead;
|
||||
use tokio::io::AsyncWrite;
|
||||
|
@ -86,11 +86,11 @@ struct ClientSessionMemoryCache(Mutex<HashMap<Vec<u8>, Vec<u8>>>);
|
|||
|
||||
impl StoresClientSessions for ClientSessionMemoryCache {
|
||||
fn get(&self, key: &[u8]) -> Option<Vec<u8>> {
|
||||
self.0.lock().unwrap().get(key).cloned()
|
||||
self.0.lock().get(key).cloned()
|
||||
}
|
||||
|
||||
fn put(&self, key: Vec<u8>, value: Vec<u8>) -> bool {
|
||||
let mut sessions = self.0.lock().unwrap();
|
||||
let mut sessions = self.0.lock();
|
||||
// TODO(bnoordhuis) Evict sessions LRU-style instead of arbitrarily.
|
||||
while sessions.len() >= 1024 {
|
||||
let key = sessions.keys().next().unwrap().clone();
|
||||
|
@ -511,7 +511,6 @@ impl ReadHalf {
|
|||
.unwrap_or_else(|_| panic!("Arc::<Shared>::try_unwrap() failed"))
|
||||
.tls_stream
|
||||
.into_inner()
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -597,7 +596,7 @@ impl Shared {
|
|||
let shared_waker = self.new_shared_waker();
|
||||
let mut cx = Context::from_waker(&shared_waker);
|
||||
|
||||
let mut tls_stream = self.tls_stream.lock().unwrap();
|
||||
let mut tls_stream = self.tls_stream.lock();
|
||||
f(Pin::new(&mut tls_stream), &mut cx)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use async_trait::async_trait;
|
||||
use deno_core::error::type_error;
|
||||
use deno_core::parking_lot::Mutex;
|
||||
use deno_core::url::Url;
|
||||
use deno_core::ZeroCopyBuf;
|
||||
use serde::Deserialize;
|
||||
|
@ -8,7 +9,6 @@ use std::collections::HashMap;
|
|||
use std::fmt::Debug;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
|
||||
use deno_core::error::AnyError;
|
||||
use uuid::Uuid;
|
||||
|
@ -26,7 +26,7 @@ pub struct BlobStore {
|
|||
impl BlobStore {
|
||||
pub fn insert_part(&self, part: Box<dyn BlobPart + Send + Sync>) -> Uuid {
|
||||
let id = Uuid::new_v4();
|
||||
let mut parts = self.parts.lock().unwrap();
|
||||
let mut parts = self.parts.lock();
|
||||
parts.insert(id, Arc::new(part));
|
||||
id
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ impl BlobStore {
|
|||
&self,
|
||||
id: &Uuid,
|
||||
) -> Option<Arc<Box<dyn BlobPart + Send + Sync>>> {
|
||||
let parts = self.parts.lock().unwrap();
|
||||
let parts = self.parts.lock();
|
||||
let part = parts.get(&id);
|
||||
part.cloned()
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ impl BlobStore {
|
|||
&self,
|
||||
id: &Uuid,
|
||||
) -> Option<Arc<Box<dyn BlobPart + Send + Sync>>> {
|
||||
let mut parts = self.parts.lock().unwrap();
|
||||
let mut parts = self.parts.lock();
|
||||
parts.remove(&id)
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ impl BlobStore {
|
|||
&self,
|
||||
mut url: Url,
|
||||
) -> Result<Option<Arc<Blob>>, AnyError> {
|
||||
let blob_store = self.object_urls.lock().unwrap();
|
||||
let blob_store = self.object_urls.lock();
|
||||
url.set_fragment(None);
|
||||
Ok(blob_store.get(&url).cloned())
|
||||
}
|
||||
|
@ -70,14 +70,14 @@ impl BlobStore {
|
|||
let id = Uuid::new_v4();
|
||||
let url = Url::parse(&format!("blob:{}/{}", origin, id)).unwrap();
|
||||
|
||||
let mut blob_store = self.object_urls.lock().unwrap();
|
||||
let mut blob_store = self.object_urls.lock();
|
||||
blob_store.insert(url.clone(), Arc::new(blob));
|
||||
|
||||
url
|
||||
}
|
||||
|
||||
pub fn remove_object_url(&self, url: &Url) {
|
||||
let mut blob_store = self.object_urls.lock().unwrap();
|
||||
let mut blob_store = self.object_urls.lock();
|
||||
blob_store.remove(&url);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
use crate::permissions::Permissions;
|
||||
use deno_core::error::bad_resource_id;
|
||||
use deno_core::error::AnyError;
|
||||
use deno_core::parking_lot::Mutex;
|
||||
use deno_core::AsyncRefCell;
|
||||
use deno_core::CancelFuture;
|
||||
use deno_core::CancelHandle;
|
||||
|
@ -99,11 +100,11 @@ fn op_fs_events_open(
|
|||
_: (),
|
||||
) -> Result<ResourceId, AnyError> {
|
||||
let (sender, receiver) = mpsc::channel::<Result<FsEvent, AnyError>>(16);
|
||||
let sender = std::sync::Mutex::new(sender);
|
||||
let sender = Mutex::new(sender);
|
||||
let mut watcher: RecommendedWatcher =
|
||||
Watcher::new_immediate(move |res: Result<NotifyEvent, NotifyError>| {
|
||||
let res2 = res.map(FsEvent::from).map_err(AnyError::from);
|
||||
let sender = sender.lock().unwrap();
|
||||
let sender = sender.lock();
|
||||
// Ignore result, if send failed it means that watcher was already closed,
|
||||
// but not all messages have been flushed.
|
||||
let _ = sender.try_send(res2);
|
||||
|
|
|
@ -5,6 +5,8 @@ use crate::fs_util::resolve_from_cwd;
|
|||
use deno_core::error::custom_error;
|
||||
use deno_core::error::uri_error;
|
||||
use deno_core::error::AnyError;
|
||||
#[cfg(test)]
|
||||
use deno_core::parking_lot::Mutex;
|
||||
use deno_core::serde::Deserialize;
|
||||
use deno_core::serde::Serialize;
|
||||
use deno_core::url;
|
||||
|
@ -21,8 +23,6 @@ use std::path::{Path, PathBuf};
|
|||
use std::sync::atomic::AtomicBool;
|
||||
#[cfg(test)]
|
||||
use std::sync::atomic::Ordering;
|
||||
#[cfg(test)]
|
||||
use std::sync::Mutex;
|
||||
|
||||
const PERMISSION_EMOJI: &str = "⚠️";
|
||||
|
||||
|
@ -1502,7 +1502,7 @@ mod tests {
|
|||
let mut perms: Permissions = Default::default();
|
||||
#[rustfmt::skip]
|
||||
{
|
||||
let _guard = PERMISSION_PROMPT_GUARD.lock().unwrap();
|
||||
let _guard = PERMISSION_PROMPT_GUARD.lock();
|
||||
set_prompt_result(true);
|
||||
assert_eq!(perms.read.request(Some(&Path::new("/foo"))), PermissionState::Granted);
|
||||
assert_eq!(perms.read.query(None), PermissionState::Prompt);
|
||||
|
@ -1599,7 +1599,7 @@ mod tests {
|
|||
hrtime: Permissions::new_hrtime(false, true),
|
||||
};
|
||||
|
||||
let _guard = PERMISSION_PROMPT_GUARD.lock().unwrap();
|
||||
let _guard = PERMISSION_PROMPT_GUARD.lock();
|
||||
|
||||
set_prompt_result(true);
|
||||
assert!(perms.read.check(&Path::new("/foo")).is_ok());
|
||||
|
@ -1652,7 +1652,7 @@ mod tests {
|
|||
hrtime: Permissions::new_hrtime(false, true),
|
||||
};
|
||||
|
||||
let _guard = PERMISSION_PROMPT_GUARD.lock().unwrap();
|
||||
let _guard = PERMISSION_PROMPT_GUARD.lock();
|
||||
|
||||
set_prompt_result(false);
|
||||
assert!(perms.read.check(&Path::new("/foo")).is_err());
|
||||
|
|
Loading…
Add table
Reference in a new issue