From 375ce63c6390cf7710210ce22f14a2b5a02cbfc3 Mon Sep 17 00:00:00 2001 From: Aaron O'Mullan Date: Tue, 9 Nov 2021 19:26:17 +0100 Subject: 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 --- runtime/js/12_io.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'runtime/js') diff --git a/runtime/js/12_io.js b/runtime/js/12_io.js index d5cf14e55..1dd162965 100644 --- a/runtime/js/12_io.js +++ b/runtime/js/12_io.js @@ -102,7 +102,7 @@ return 0; } - const nread = await core.opAsync("op_read_async", rid, buffer); + const nread = await core.read(rid, buffer); return nread === 0 ? null : nread; } @@ -111,8 +111,8 @@ return core.opSync("op_write_sync", rid, data); } - async function write(rid, data) { - return await core.opAsync("op_write_async", rid, data); + function write(rid, data) { + return core.write(rid, data); } const READ_PER_ITER = 16 * 1024; // 16kb, see https://github.com/denoland/deno/issues/10157 -- cgit v1.2.3