Skip to content

Commit

Permalink
Test whether reader.read() inside next() works
Browse files Browse the repository at this point in the history
  • Loading branch information
MattiasBuelens committed Apr 15, 2021
1 parent 7a5e30f commit 5a1e6a0
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions streams/readable-streams/from.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,37 @@ promise_test(async t => {

}, `ReadableStream.from: return() is not called when iterator completes normally`);

promise_test(async () => {

let nextCalls = 0;
let reader;
let values = ['a', 'b', 'c'];

const iterable = {
async next() {
nextCalls += 1;
if (nextCalls === 1) {
reader.read();
}
return { value: values.shift(), done: false };
},
[Symbol.asyncIterator]: () => iterable
};

const rs = ReadableStream.from(iterable);
reader = rs.getReader();

const read1 = await reader.read();
assert_object_equals(read1, { value: 'a', done: false }, 'first read should be correct');
await flushAsyncEvents();
assert_equals(nextCalls, 2, 'next() should be called two times');

const read2 = await reader.read();
assert_object_equals(read2, { value: 'c', done: false }, 'second read should be correct');
assert_equals(nextCalls, 3, 'next() should be called three times');

}, `ReadableStream.from: reader.read() inside next()`);

promise_test(async () => {

let nextCalls = 0;
Expand Down

0 comments on commit 5a1e6a0

Please sign in to comment.