diff options
author | Satya Rohith <me@satyarohith.com> | 2024-03-13 22:52:25 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-13 17:22:25 +0000 |
commit | 0fd8f549e2194223eca2d4b17f4e96cd5a0f5fd5 (patch) | |
tree | 76181b2a5f2991134f7343cfc6d4b8b755dbc333 /runtime/web_worker.rs | |
parent | b3ca3b2f25931afb350027bde87dc3d4f9a741b0 (diff) |
fix(ext/node): allow automatic worker_thread termination (#22647)
Co-authored-by: Matt Mastracci <matthew@mastracci.com>
Diffstat (limited to 'runtime/web_worker.rs')
-rw-r--r-- | runtime/web_worker.rs | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs index 07a8b374f..82da9de9e 100644 --- a/runtime/web_worker.rs +++ b/runtime/web_worker.rs @@ -5,6 +5,7 @@ use crate::permissions::PermissionsContainer; use crate::shared::maybe_transpile_source; use crate::shared::runtime; use crate::tokio_util::create_and_run_current_thread; +use crate::worker::create_op_metrics; use crate::worker::import_meta_resolve_callback; use crate::worker::validate_import_attributes_callback; use crate::worker::FormatJsErrorFn; @@ -34,7 +35,6 @@ use deno_core::ModuleCodeString; use deno_core::ModuleId; use deno_core::ModuleLoader; use deno_core::ModuleSpecifier; -use deno_core::OpMetricsSummaryTracker; use deno_core::PollEventLoopOptions; use deno_core::RuntimeOptions; use deno_core::SharedArrayBufferStore; @@ -327,6 +327,7 @@ pub struct WebWorker { id: WorkerId, pub js_runtime: JsRuntime, pub name: String, + close_on_idle: bool, internal_handle: WebWorkerInternalHandle, pub worker_type: WebWorkerType, pub main_module: ModuleSpecifier, @@ -359,6 +360,8 @@ pub struct WebWorkerOptions { pub cache_storage_dir: Option<std::path::PathBuf>, pub stdio: Stdio, pub feature_checker: Arc<FeatureChecker>, + pub strace_ops: Option<Vec<String>>, + pub close_on_idle: bool, pub maybe_worker_metadata: Option<JsMessageData>, } @@ -511,17 +514,11 @@ impl WebWorker { #[cfg(feature = "only_snapshotted_js_sources")] options.startup_snapshot.as_ref().expect("A user snapshot was not provided, even though 'only_snapshotted_js_sources' is used."); - // Hook up the summary metrics if the user or subcommand requested them - let (op_summary_metrics, op_metrics_factory_fn) = - if options.bootstrap.enable_op_summary_metrics { - let op_summary_metrics = Rc::new(OpMetricsSummaryTracker::default()); - ( - Some(op_summary_metrics.clone()), - Some(op_summary_metrics.op_metrics_factory_fn(|_| true)), - ) - } else { - (None, None) - }; + // Get our op metrics + let (op_summary_metrics, op_metrics_factory_fn) = create_op_metrics( + options.bootstrap.enable_op_summary_metrics, + options.strace_ops, + ); let mut js_runtime = JsRuntime::new(RuntimeOptions { module_loader: Some(options.module_loader.clone()), @@ -606,6 +603,7 @@ impl WebWorker { main_module, poll_for_messages_fn: None, bootstrap_fn_global: Some(bootstrap_fn_global), + close_on_idle: options.close_on_idle, maybe_worker_metadata: options.maybe_worker_metadata, }, external_handle, @@ -759,6 +757,10 @@ impl WebWorker { return Poll::Ready(Err(e)); } + if self.close_on_idle { + return Poll::Ready(Ok(())); + } + // TODO(mmastrac): we don't want to test this w/classic workers because // WPT triggers a failure here. This is only exposed via --enable-testing-features-do-not-use. if self.worker_type == WebWorkerType::Module { |