summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-05-01 17:40:00 +0200
committerGitHub <noreply@github.com>2023-05-01 17:40:00 +0200
commitdcf391ffed3850f9026d88b146e156375c4619d4 (patch)
tree2134755e8abbecaba1d42703fe727ae701ee390c /core
parent6728ad4203d731e555dabf89ec6157f113454ce6 (diff)
refactor: migrate async ops to generated wrappers (#18937)
Migrates some of existing async ops to generated wrappers introduced in https://github.com/denoland/deno/pull/18887. As a result "core.opAsync2" was removed. I will follow up with more PRs that migrate all the async ops to generated wrappers.
Diffstat (limited to 'core')
-rw-r--r--core/01_core.js26
-rw-r--r--core/examples/http_bench_json_ops/http_bench_json_ops.js32
-rw-r--r--core/runtime.rs4
3 files changed, 16 insertions, 46 deletions
diff --git a/core/01_core.js b/core/01_core.js
index 72cbe31f7..403a04297 100644
--- a/core/01_core.js
+++ b/core/01_core.js
@@ -564,31 +564,6 @@ for (let i = 0; i < 10; i++) {
return (ops[opName] = fn);
}
- function opAsync2(name, arg0, arg1) {
- const id = nextPromiseId++;
- try {
- const maybeResult = asyncOps[name](id, arg0, arg1);
- if (maybeResult !== undefined) {
- movePromise(id);
- return unwrapOpResultNewPromise(id, maybeResult, opAsync2);
- }
- } catch (err) {
- movePromise(id);
- if (!ReflectHas(asyncOps, name)) {
- return PromiseReject(new TypeError(`${name} is not a registered op`));
- }
- ErrorCaptureStackTrace(err, opAsync2);
- return PromiseReject(err);
- }
- let promise = PromisePrototypeThen(
- setPromise(id),
- unwrapOpError(eventLoopTick),
- );
- promise = handleOpCallTracing(name, id, promise);
- promise[promiseIdSymbol] = id;
- return promise;
- }
-
function opAsync(name, ...args) {
const id = nextPromiseId++;
try {
@@ -823,7 +798,6 @@ for (let i = 0; i < 10; i++) {
asyncStub,
generateAsyncOpHandler,
opAsync,
- opAsync2,
resources,
metrics,
registerErrorBuilder,
diff --git a/core/examples/http_bench_json_ops/http_bench_json_ops.js b/core/examples/http_bench_json_ops/http_bench_json_ops.js
index 0c3b5be13..beb6c90e4 100644
--- a/core/examples/http_bench_json_ops/http_bench_json_ops.js
+++ b/core/examples/http_bench_json_ops/http_bench_json_ops.js
@@ -3,7 +3,16 @@
// then write this fixed 'responseBuf'. The point of this benchmark is to
// exercise the event loop in a simple yet semi-realistic way.
-const { ops, opAsync, opAsync2 } = Deno.core;
+// deno-lint-ignore-file camelcase
+
+const { op_listen } = Deno.core.ops;
+const {
+ op_accept,
+ op_read_socket,
+} = core.generateAsyncOpHandler(
+ "op_accept",
+ "op_read_socket",
+);
const requestBuf = new Uint8Array(64 * 1024);
const responseBuf = new Uint8Array(
@@ -12,24 +21,10 @@ const responseBuf = new Uint8Array(
.map((c) => c.charCodeAt(0)),
);
-/** Listens on 0.0.0.0:4570, returns rid. */
-function listen() {
- return ops.op_listen();
-}
-
-/** Accepts a connection, returns rid. */
-function accept(serverRid) {
- return opAsync("op_accept", serverRid);
-}
-
-function read(serverRid, buf) {
- return opAsync2("op_read_socket", serverRid, buf);
-}
-
async function serve(rid) {
try {
while (true) {
- await read(rid, requestBuf);
+ await op_read_socket(rid, requestBuf);
if (!ops.op_try_write(rid, responseBuf)) {
await Deno.core.writeAll(rid, responseBuf);
}
@@ -41,11 +36,12 @@ async function serve(rid) {
}
async function main() {
- const listenerRid = listen();
+ /** Listens on 0.0.0.0:4570, returns rid. */
+ const listenerRid = op_listen();
Deno.core.print(`http_bench_ops listening on http://127.0.0.1:4570/\n`);
while (true) {
- const rid = await accept(listenerRid);
+ const rid = await op_accept(listenerRid);
serve(rid);
}
}
diff --git a/core/runtime.rs b/core/runtime.rs
index e6c365e42..46256b8d8 100644
--- a/core/runtime.rs
+++ b/core/runtime.rs
@@ -2765,9 +2765,9 @@ pub mod tests {
.execute_script_static(
"filename.js",
r#"
-
+ const { op_test } = Deno.core.generateAsyncOpHandler("op_test");
let zero_copy_a = new Uint8Array([0]);
- Deno.core.opAsync2("op_test", null, zero_copy_a);
+ op_test(null, zero_copy_a);
"#,
)
.unwrap();