Skip to content

Commit 458c92b

Browse files
ChALkeRaduh95
authored andcommitted
events: don't call resume after close
PR-URL: #60548Fixes: #60507 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
1 parent 2bf990b commit 458c92b

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

‎lib/events.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,7 @@ function on(emitter, event, options = kEmptyObject) {
10741074
constvalue=unconsumedEvents.shift();
10751075
size--;
10761076
if(paused&&size<lowWatermark){
1077-
emitter.resume();
1077+
emitter.resume();// Can not be finished yet
10781078
paused=false;
10791079
}
10801080
returnPromiseResolve(createIterResult(value,false));
@@ -1191,6 +1191,7 @@ function on(emitter, event, options = kEmptyObject) {
11911191
abortListenerDisposable?.[SymbolDispose]();
11921192
removeAll();
11931193
finished=true;
1194+
paused=false;
11941195
constdoneResult=createIterResult(undefined,true);
11951196
while(!unconsumedPromises.isEmpty()){
11961197
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+
Array(1e4).fill(0).map((_,i)=>i).join('\n'),// More that 2 * highWaterMark
2021
];
2122

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

47+
// Same as testSimple, but with Readable.from() instead of fs.createReadStream
48+
asyncfunctiontestReadableFrom(){
49+
for(constfileContentoftestContents){
50+
constreadable=Readable.from([fileContent]);
51+
constrli=readline.createInterface({
52+
input: readable,
53+
crlfDelay: Infinity
54+
});
55+
56+
constiteratedLines=[];
57+
forawait(constkofrli){
58+
iteratedLines.push(k);
59+
}
60+
61+
constexpectedLines=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
asyncfunctiontestMutual(){
4771
for(constfileContentoftestContents){
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)