diff options
author | Leo Kettmeir <crowlkats@toaxl.com> | 2022-07-18 22:24:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-18 22:24:35 +0200 |
commit | 2bebdc9116f0824f0eb6241445de6fb1925f4c15 (patch) | |
tree | 55b2dbe9f7022b7693165b75a97e26cef0c2eb9c /ext/web/06_streams.js | |
parent | 9eb70bdb5fda8e66895e0e4cc1f356c2717f74c5 (diff) |
feat(unstable): Ability to ref/unref "Child" in "Deno.spawnChild()" API (#15151)
Co-authored-by: Bartek IwaĆczuk <biwanczuk@gmail.com>
Co-authored-by: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'ext/web/06_streams.js')
-rw-r--r-- | ext/web/06_streams.js | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/ext/web/06_streams.js b/ext/web/06_streams.js index 9ec028e4b..7f67e81ed 100644 --- a/ext/web/06_streams.js +++ b/ext/web/06_streams.js @@ -647,13 +647,28 @@ const DEFAULT_CHUNK_SIZE = 64 * 1024; // 64 KiB - function readableStreamForRid(rid) { + /** + * @callback unrefCallback + * @param {Promise} promise + * @returns {undefined} + */ + /** + * @param {number} rid + * @param {unrefCallback=} unrefCallback + * @returns {ReadableStream<Uint8Array>} + */ + function readableStreamForRid(rid, unrefCallback) { const stream = new ReadableStream({ type: "bytes", async pull(controller) { const v = controller.byobRequest.view; try { - const bytesRead = await core.read(rid, v); + const promise = core.read(rid, v); + + unrefCallback?.(promise); + + const bytesRead = await promise; + if (bytesRead === 0) { core.tryClose(rid); controller.close(); |