summaryrefslogtreecommitdiff
path: root/runtime/ops/web_worker.rs
diff options
context:
space:
mode:
authorMatt Mastracci <matthew@mastracci.com>2023-03-17 12:22:15 -0600
committerGitHub <noreply@github.com>2023-03-17 18:22:15 +0000
commite55b448730160a6e4df9815a268d4049ac89deab (patch)
tree35d80fd60f2f1d1d06903caff256484a7d703d76 /runtime/ops/web_worker.rs
parent0bc6bf5d33b8198253954d7f04558270de45c925 (diff)
feat(core) deno_core::extension! macro to simplify extension registration (#18210)
This implements two macros to simplify extension registration and centralize a lot of the boilerplate as a base for future improvements: * `deno_core::ops!` registers a block of `#[op]`s, optionally with type parameters, useful for places where we share lists of ops * `deno_core::extension!` is used to register an extension, and creates two methods that can be used at runtime/snapshot generation time: `init_ops` and `init_ops_and_esm`. --------- Co-authored-by: Bartek IwaƄczuk <biwanczuk@gmail.com>
Diffstat (limited to 'runtime/ops/web_worker.rs')
-rw-r--r--runtime/ops/web_worker.rs24
1 files changed, 11 insertions, 13 deletions
diff --git a/runtime/ops/web_worker.rs b/runtime/ops/web_worker.rs
index 617615424..45137913e 100644
--- a/runtime/ops/web_worker.rs
+++ b/runtime/ops/web_worker.rs
@@ -8,7 +8,6 @@ use deno_core::error::AnyError;
use deno_core::op;
use deno_core::CancelFuture;
-use deno_core::Extension;
use deno_core::OpState;
use deno_web::JsMessageData;
use std::cell::RefCell;
@@ -16,18 +15,17 @@ use std::rc::Rc;
use self::sync_fetch::op_worker_sync_fetch;
-pub fn init() -> Extension {
- Extension::builder("deno_web_worker")
- .ops(vec![
- op_worker_post_message::decl(),
- op_worker_recv_message::decl(),
- // Notify host that guest worker closes.
- op_worker_close::decl(),
- op_worker_get_type::decl(),
- op_worker_sync_fetch::decl(),
- ])
- .build()
-}
+deno_core::extension!(
+ deno_web_worker,
+ ops = [
+ op_worker_post_message,
+ op_worker_recv_message,
+ // Notify host that guest worker closes.
+ op_worker_close,
+ op_worker_get_type,
+ op_worker_sync_fetch,
+ ]
+);
#[op]
fn op_worker_post_message(