diff --git a/cli/tools/lint/plugins.rs b/cli/tools/lint/plugins.rs index 0ee09b867f..10752097d1 100644 --- a/cli/tools/lint/plugins.rs +++ b/cli/tools/lint/plugins.rs @@ -25,9 +25,8 @@ use deno_runtime::deno_permissions::PermissionsContainer; use deno_runtime::tokio_util; use deno_runtime::worker::MainWorker; use deno_runtime::WorkerExecutionMode; -use tokio::sync::mpsc::channel; -use tokio::sync::mpsc::Receiver; -use tokio::sync::mpsc::Sender; +use tokio::sync::mpsc; +use tokio::sync::oneshot; use crate::args::DenoSubcommand; use crate::args::Flags; @@ -42,6 +41,7 @@ pub enum PluginHostRequest { LoadPlugins { specifiers: Vec, exclude_rules: Option>, + tx: oneshot::Sender, }, Run { serialized_ast: Vec, @@ -49,6 +49,7 @@ pub enum PluginHostRequest { source_text_info: SourceTextInfo, utf16_map: Utf16Map, maybe_token: Option, + tx: oneshot::Sender, }, } @@ -102,8 +103,7 @@ v8_static_strings! { #[derive(Debug)] pub struct PluginHostProxy { - tx: Sender, - rx: Arc>>, + tx: mpsc::Sender, pub(crate) plugin_info: Arc>>, #[allow(unused)] join_handle: std::thread::JoinHandle>, @@ -127,14 +127,12 @@ pub struct PluginHost { worker: MainWorker, install_plugins_fn: Rc>, run_plugins_for_file_fn: Rc>, - tx: Sender, - rx: Receiver, + rx: mpsc::Receiver, } async fn create_plugin_runner_inner( logger: PluginLogger, - rx_req: Receiver, - tx_res: Sender, + rx_req: mpsc::Receiver, ) -> Result { let flags = Flags { subcommand: DenoSubcommand::Lint(LintFlags::default()), @@ -202,7 +200,6 @@ async fn create_plugin_runner_inner( worker, install_plugins_fn, run_plugins_for_file_fn, - tx: tx_res, rx: rx_req, }) } @@ -228,8 +225,7 @@ impl PluginInfo { impl PluginHost { fn create(logger: PluginLogger) -> Result { - let (tx_req, rx_req) = channel(10); - let (tx_res, rx_res) = channel(10); + let (tx_req, rx_req) = mpsc::channel(10); let logger_ = logger.clone(); let join_handle = std::thread::spawn(move || { @@ -237,8 +233,7 @@ impl PluginHost { log::debug!("Lint PluginHost thread spawned"); let start = std::time::Instant::now(); let fut = async move { - let runner = - create_plugin_runner_inner(logger.clone(), rx_req, tx_res).await?; + let runner = create_plugin_runner_inner(logger.clone(), rx_req).await?; log::debug!("Lint PlugibnHost running loop"); runner.run_loop().await?; log::debug!( @@ -253,7 +248,6 @@ impl PluginHost { let proxy = PluginHostProxy { tx: tx_req, - rx: Arc::new(tokio::sync::Mutex::new(rx_res)), plugin_info: Arc::new(Mutex::new(vec![])), join_handle, }; @@ -269,9 +263,10 @@ impl PluginHost { PluginHostRequest::LoadPlugins { specifiers, exclude_rules, + tx, } => { let r = self.load_plugins(specifiers, exclude_rules).await; - let _ = self.tx.send(PluginHostResponse::LoadPlugin(r)).await; + let _ = tx.send(PluginHostResponse::LoadPlugin(r)); } PluginHostRequest::Run { serialized_ast, @@ -279,6 +274,7 @@ impl PluginHost { source_text_info, utf16_map, maybe_token, + tx, } => { let start = std::time::Instant::now(); let r = match self.run_plugins( @@ -295,7 +291,7 @@ impl PluginHost { "Running plugins lint rules took {:?}", std::time::Instant::now() - start ); - let _ = self.tx.send(PluginHostResponse::Run(r)).await; + let _ = tx.send(PluginHostResponse::Run(r)); } } } @@ -452,16 +448,17 @@ impl PluginHostProxy { specifiers: Vec, exclude_rules: Option>, ) -> Result<(), AnyError> { + let (tx, rx) = oneshot::channel(); self .tx .send(PluginHostRequest::LoadPlugins { specifiers, exclude_rules, + tx, }) .await?; - let mut rx = self.rx.lock().await; - if let Some(val) = rx.recv().await { + if let Ok(val) = rx.await { let PluginHostResponse::LoadPlugin(result) = val else { unreachable!() }; @@ -480,6 +477,7 @@ impl PluginHostProxy { utf16_map: Utf16Map, maybe_token: Option, ) -> Result, AnyError> { + let (tx, rx) = oneshot::channel(); self .tx .send(PluginHostRequest::Run { @@ -488,11 +486,11 @@ impl PluginHostProxy { source_text_info, utf16_map, maybe_token, + tx, }) .await?; - let mut rx = self.rx.lock().await; - if let Some(PluginHostResponse::Run(diagnostics_result)) = rx.recv().await { + if let Ok(PluginHostResponse::Run(diagnostics_result)) = rx.await { return diagnostics_result; } bail!("Plugin host has closed")