summaryrefslogtreecommitdiff
path: root/ext/web/06_streams.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/web/06_streams.js')
-rw-r--r--ext/web/06_streams.js19
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();