diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2022-04-20 18:16:44 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-20 18:16:44 +0530 |
commit | 57a8fc37fc99491fa2559694f78af52a597bc501 (patch) | |
tree | b6d3bd41faa72dfeec4643e5fbb68a669ca03e79 /ext/net/01_net.js | |
parent | 3833d37b15e1e8380efd1a9eea956a8b33745555 (diff) |
perf(http): optimize `ReadableStream`s backed by a resource (#14284)
Diffstat (limited to 'ext/net/01_net.js')
-rw-r--r-- | ext/net/01_net.js | 30 |
1 files changed, 1 insertions, 29 deletions
diff --git a/ext/net/01_net.js b/ext/net/01_net.js index 48cbfaaab..fde75fe56 100644 --- a/ext/net/01_net.js +++ b/ext/net/01_net.js @@ -4,7 +4,7 @@ ((window) => { const core = window.Deno.core; const { BadResourcePrototype, InterruptedPrototype } = core; - const { ReadableStream, WritableStream } = window.__bootstrap.streams; + const { WritableStream, readableStreamForRid } = window.__bootstrap.streams; const { Error, ObjectPrototypeIsPrototypeOf, @@ -65,8 +65,6 @@ return core.opAsync("op_dns_resolve", { query, recordType, options }); } - const DEFAULT_CHUNK_SIZE = 64 * 1024; - function tryClose(rid) { try { core.close(rid); @@ -75,32 +73,6 @@ } } - function readableStreamForRid(rid) { - return new ReadableStream({ - type: "bytes", - async pull(controller) { - const v = controller.byobRequest.view; - try { - const bytesRead = await read(rid, v); - if (bytesRead === null) { - tryClose(rid); - controller.close(); - controller.byobRequest.respond(0); - } else { - controller.byobRequest.respond(bytesRead); - } - } catch (e) { - controller.error(e); - tryClose(rid); - } - }, - cancel() { - tryClose(rid); - }, - autoAllocateChunkSize: DEFAULT_CHUNK_SIZE, - }); - } - function writableStreamForRid(rid) { return new WritableStream({ async write(chunk, controller) { |