Skip to content

Commit 9bedc04

Browse files
committed
events: don't call resume after close
1 parent dbe45b7 commit 9bedc04

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

lib/events.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,7 @@ function on(emitter, event, options = kEmptyObject) {
10711071
const value = unconsumedEvents.shift();
10721072
size--;
10731073
if (paused && size < lowWatermark) {
1074-
emitter.resume();
1074+
emitter.resume(); // Can not be finished yet
10751075
paused = false;
10761076
}
10771077
return PromiseResolve(createIterResult(value, false));
@@ -1188,6 +1188,7 @@ function on(emitter, event, options = kEmptyObject) {
11881188
abortListenerDisposable?.[SymbolDispose]();
11891189
removeAll();
11901190
finished = true;
1191+
paused = false;
11911192
const doneResult = createIterResult(undefined, true);
11921193
while (!unconsumedPromises.isEmpty()) {
11931194
unconsumedPromises.shift().resolve(doneResult);

test/parallel/test-readline-async-iterators.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const testContents = [
1717
'line 1',
1818
'line 1\nline 2 南越国是前203年至前111年存在于岭南地区的一个国家\nline 3\ntrailing',
1919
'line 1\nline 2\nline 3 ends with newline\n',
20+
AArray(1e4).fill(0).map((_, i) => i).join('\n'), // More that 2 * highWaterMark
2021
];
2122

2223
async function testSimple() {
@@ -43,6 +44,29 @@ async function testSimple() {
4344
}
4445
}
4546

47+
// Same as testSimple, but with Readable.from() instead of fs.createReadStream
48+
async function testReadableFrom() {
49+
for (const fileContent of testContents) {
50+
const readable = Readable.from([fileContent]);
51+
const rli = readline.createInterface({
52+
input: readable,
53+
crlfDelay: Infinity
54+
});
55+
56+
const iteratedLines = [];
57+
for await (const k of rli) {
58+
iteratedLines.push(k);
59+
}
60+
61+
const expectedLines = fileContent.split('\n');
62+
if (expectedLines[expectedLines.length - 1] === '') {
63+
expectedLines.pop();
64+
}
65+
assert.deepStrictEqual(iteratedLines, expectedLines);
66+
assert.strictEqual(iteratedLines.join(''), fileContent.replace(/\n/g, ''));
67+
}
68+
}
69+
4670
async function testMutual() {
4771
for (const fileContent of testContents) {
4872
fs.writeFileSync(filename, fileContent);
@@ -115,6 +139,7 @@ async function testSlowStreamForLeaks() {
115139
}
116140

117141
testSimple()
142+
.then(testReadableFrom)
118143
.then(testMutual)
119144
.then(testSlowStreamForLeaks)
120145
.then(common.mustCall());

0 commit comments

Comments
 (0)