diff options
Diffstat (limited to 'core/examples')
-rw-r--r-- | core/examples/http_bench_json_ops/http_bench_json_ops.js | 32 |
1 files changed, 14 insertions, 18 deletions
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); } } |