summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2021-07-06 23:48:01 -0400
committerGitHub <noreply@github.com>2021-07-06 23:48:01 -0400
commit7fc0e8ec8cd4b18ba10a04cf0ac2bee48826de3d (patch)
tree70e078538ae0f3467e8a519b918ae936587ce2d4 /cli
parent78ac19f51f48984ea16f97a0c574fa507544b8d5 (diff)
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
Diffstat (limited to 'cli')
-rw-r--r--cli/file_fetcher.rs6
-rw-r--r--cli/file_watcher.rs6
-rw-r--r--cli/lsp/config.rs24
-rw-r--r--cli/lsp/performance.rs12
-rw-r--r--cli/lsp/sources.rs27
-rw-r--r--cli/main.rs2
-rw-r--r--cli/module_graph.rs36
-rw-r--r--cli/ops/runtime_compiler.rs2
-rw-r--r--cli/program_state.rs16
-rw-r--r--cli/tools/doc.rs2
-rw-r--r--cli/tools/installer.rs6
-rw-r--r--cli/tools/repl.rs12
-rw-r--r--cli/tsc.rs10
13 files changed, 75 insertions, 86 deletions
diff --git a/cli/file_fetcher.rs b/cli/file_fetcher.rs
index a326d130e..61cf1dae6 100644
--- a/cli/file_fetcher.rs
+++ b/cli/file_fetcher.rs
@@ -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)
}
}
diff --git a/cli/file_watcher.rs b/cli/file_watcher.rs
index 7251dbe8c..aee3fe787 100644
--- a/cli/file_watcher.rs
+++ b/cli/file_watcher.rs
@@ -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);
}
}
diff --git a/cli/lsp/config.rs b/cli/lsp/config.rs
index 0d3bf748e..95e0bb534 100644
--- a/cli/lsp/config.rs
+++ b/cli/lsp/config.rs
@@ -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)
diff --git a/cli/lsp/performance.rs b/cli/lsp/performance.rs
index 87e29f3db..74af38ec1 100644
--- a/cli/lsp/performance.rs
+++ b/cli/lsp/performance.rs
@@ -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()
}
}
diff --git a/cli/lsp/sources.rs b/cli/lsp/sources.rs
index 37f8b6bce..1b7d6f3fa 100644
--- a/cli/lsp/sources.rs
+++ b/cli/lsp/sources.rs
@@ -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);
diff --git a/cli/main.rs b/cli/main.rs
index eb7b4d333..6069f4479 100644
--- a/cli/main.rs
+++ b/cli/main.rs
@@ -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(
diff --git a/cli/module_graph.rs b/cli/module_graph.rs
index e56f26c15..8ec439a8e 100644
--- a/cli/module_graph.rs
+++ b/cli/module_graph.rs
@@ -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 {
diff --git a/cli/ops/runtime_compiler.rs b/cli/ops/runtime_compiler.rs
index dd500077a..b11d79500 100644
--- a/cli/ops/runtime_compiler.rs
+++ b/cli/ops/runtime_compiler.rs
@@ -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);
diff --git a/cli/program_state.rs b/cli/program_state.rs
index 5bb60906e..264b22729 100644
--- a/cli/program_state.rs
+++ b/cli/program_state.rs
@@ -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 {
diff --git a/cli/tools/doc.rs b/cli/tools/doc.rs
index b1ab0174f..6e4d39954 100644
--- a/cli/tools/doc.rs
+++ b/cli/tools/doc.rs
@@ -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>;
diff --git a/cli/tools/installer.rs b/cli/tools/installer.rs
index 5877494d1..b6bb8bbb2 100644
--- a/cli/tools/installer.rs
+++ b/cli/tools/installer.rs
@@ -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();
diff --git a/cli/tools/repl.rs b/cli/tools/repl.rs
index 662e1a8d7..e3dbc5be8 100644
--- a/cli/tools/repl.rs
+++ b/cli/tools/repl.rs
@@ -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(())
}
}
diff --git a/cli/tsc.rs b/cli/tsc.rs
index 59b4ac81a..593dd24fb 100644
--- a/cli/tsc.rs
+++ b/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>,