Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions lib/internal/blob.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,15 @@ function createBlobReaderStream(reader) {
this.pendingPulls = [];
// Register a wakeup callback that the C++ side can invoke
// when new data is available after a STATUS_BLOCK.
let immediate;
reader.setWakeup(() => {
if (this.pendingPulls.length > 0) {
this.readNext(c);
if (this.pendingPulls.length > 0 &&
typeof immediate === 'undefined') {
// Postpone the execution to the next steps of the event loop
immediate = setImmediate(() => {
immediate = undefined;
this.readNext(c);
});
}
});
},
Expand Down Expand Up @@ -544,7 +550,16 @@ const kMaxBatchChunks = 16;
async function* createBlobReaderIterable(reader, options = kEmptyObject) {
const { getReadError } = options;
let wakeup = PromiseWithResolvers();
reader.setWakeup(wakeup.resolve);
let immediate;
reader.setWakeup(() => {
if (typeof immediate === 'undefined') {
// Postpone the execution to the next steps of the event loop
immediate = setImmediate(() => {
immediate = undefined;
wakeup.resolve?.();
});
}
});

try {
while (true) {
Expand Down Expand Up @@ -591,7 +606,6 @@ async function* createBlobReaderIterable(reader, options = kEmptyObject) {
if (blocked) {
const fin = await wakeup.promise;
wakeup = PromiseWithResolvers();
reader.setWakeup(wakeup.resolve);
// If the wakeup was triggered by FIN (EndReadable), the DataQueue
// is capped. Continue the loop to pull again -- the next pull will
// return EOS. Without this, a race between the data notification
Expand Down
Loading