summaryrefslogtreecommitdiff
path: root/cli/ops/worker_host.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2020-01-29 18:54:23 +0100
committerGitHub <noreply@github.com>2020-01-29 18:54:23 +0100
commit161adfc51b750a7c8c62a898ea9948c2ad5b6cd9 (patch)
tree6d53db2a4acd30207372f665a3ba463e26db6fcf /cli/ops/worker_host.rs
parentd14864c57cebbd1d5bc18b8a9e05e522eb9987b0 (diff)
workers: proper TS libs, more spec-compliant APIs (#3812)
* split lib.deno_main.d.ts into: - lib.deno.shared_globals.d.ts - lib.deno.window.d.ts - lib.deno.worker.d.ts * remove no longer used libs: - lib.deno_main.d.ts - lib.deno_worker.d.ts * change module loading to use proper TS library for compilation * align to Worker API spec: - Worker.terminate() - self.close() - self.name
Diffstat (limited to 'cli/ops/worker_host.rs')
-rw-r--r--cli/ops/worker_host.rs19
1 files changed, 13 insertions, 6 deletions
diff --git a/cli/ops/worker_host.rs b/cli/ops/worker_host.rs
index 976c32219..a1509d2f7 100644
--- a/cli/ops/worker_host.rs
+++ b/cli/ops/worker_host.rs
@@ -4,7 +4,6 @@ use crate::deno_error::bad_resource;
use crate::deno_error::js_check;
use crate::deno_error::DenoError;
use crate::deno_error::ErrorKind;
-use crate::deno_error::GetErrorKind;
use crate::fmt_errors::JSError;
use crate::ops::json_op;
use crate::startup_data;
@@ -60,6 +59,7 @@ pub fn init(i: &mut Isolate, s: &ThreadSafeState) {
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
struct CreateWorkerArgs {
+ name: Option<String>,
specifier: String,
has_source_code: bool,
source_code: String,
@@ -89,23 +89,28 @@ fn op_create_worker(
}
let (int, ext) = ThreadSafeState::create_channels();
- let child_state = ThreadSafeState::new(
+ let child_state = ThreadSafeState::new_for_worker(
state.global_state.clone(),
Some(parent_state.permissions.clone()), // by default share with parent
Some(module_specifier.clone()),
int,
)?;
+ let worker_name = if let Some(name) = args.name {
+ name
+ } else {
+ // TODO(bartlomieju): change it to something more descriptive
+ format!("USER-WORKER-{}", specifier)
+ };
+
// TODO: add a new option to make child worker not sharing permissions
// with parent (aka .clone(), requests from child won't reflect in parent)
- // TODO(bartlomieju): get it from "name" argument when creating worker
- let name = format!("USER-WORKER-{}", specifier);
let mut worker = WebWorker::new(
- name.to_string(),
+ worker_name.to_string(),
startup_data::deno_isolate_init(),
child_state,
ext,
);
- let script = format!("bootstrapWorkerRuntime(\"{}\")", name);
+ let script = format!("bootstrapWorkerRuntime(\"{}\")", worker_name);
js_check(worker.execute(&script));
js_check(worker.execute("runWorkerMessageLoop()"));
@@ -158,6 +163,8 @@ impl Future for WorkerPollFuture {
}
fn serialize_worker_result(result: Result<(), ErrBox>) -> Value {
+ use crate::deno_error::GetErrorKind;
+
if let Err(error) = result {
match error.kind() {
ErrorKind::JSError => {