summaryrefslogtreecommitdiff
path: root/core/examples/http_bench_json_ops.js
diff options
context:
space:
mode:
authorAaron O'Mullan <aaron.omullan@gmail.com>2021-11-09 19:26:17 +0100
committerGitHub <noreply@github.com>2021-11-09 19:26:17 +0100
commit375ce63c6390cf7710210ce22f14a2b5a02cbfc3 (patch)
tree85100876e5e0b50514385ae3c7ce08493c82b38b /core/examples/http_bench_json_ops.js
parent1eae6c139ee1dac28df57d67d993792b773fa1ff (diff)
feat(core): streams (#12596)
This allows resources to be "streams" by implementing read/write/shutdown. These streams are implicit since their nature (read/write/duplex) isn't known until called, but we could easily add another method to explicitly tag resources as streams. `op_read/op_write/op_shutdown` are now builtin ops provided by `deno_core` Note: this current implementation is simple & straightforward but it results in an additional alloc per read/write call Closes #12556
Diffstat (limited to 'core/examples/http_bench_json_ops.js')
-rw-r--r--core/examples/http_bench_json_ops.js23
1 files changed, 3 insertions, 20 deletions
diff --git a/core/examples/http_bench_json_ops.js b/core/examples/http_bench_json_ops.js
index ad36dd674..12d79a0ce 100644
--- a/core/examples/http_bench_json_ops.js
+++ b/core/examples/http_bench_json_ops.js
@@ -19,28 +19,11 @@ function accept(serverRid) {
return Deno.core.opAsync("accept", serverRid);
}
-/**
- * Reads a packet from the rid, presumably an http request. data is ignored.
- * Returns bytes read.
- */
-function read(rid, data) {
- return Deno.core.opAsync("read", rid, data);
-}
-
-/** Writes a fixed HTTP response to the socket rid. Returns bytes written. */
-function write(rid, data) {
- return Deno.core.opAsync("write", rid, data);
-}
-
-function close(rid) {
- Deno.core.opSync("close", rid);
-}
-
async function serve(rid) {
try {
while (true) {
- await read(rid, requestBuf);
- await write(rid, responseBuf);
+ await Deno.core.read(rid, requestBuf);
+ await Deno.core.write(rid, responseBuf);
}
} catch (e) {
if (
@@ -50,7 +33,7 @@ async function serve(rid) {
throw e;
}
}
- close(rid);
+ Deno.core.close(rid);
}
async function main() {