-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stream: always defer 'readable' with nextTick
Fixes: #3203
- Loading branch information
Showing
8 changed files
with
118 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
test/parallel/test-stream-readable-object-multi-push-async.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const { Readable } = require('stream'); | ||
|
||
const MAX = 42; | ||
const BATCH = 10; | ||
|
||
const readable = new Readable({ | ||
objectMode: true, | ||
read: common.mustCall(function() { | ||
console.log('>> READ'); | ||
fetchData((err, data) => { | ||
if (err) { | ||
this.destroy(err); | ||
return; | ||
} | ||
|
||
if (data.length === 0) { | ||
console.log('pushing null'); | ||
this.push(null); | ||
return; | ||
} | ||
|
||
console.log('pushing'); | ||
data.forEach((d) => this.push(d)); | ||
}); | ||
}, Math.floor(MAX / BATCH) + 2) | ||
}); | ||
|
||
let i = 0; | ||
function fetchData(cb) { | ||
if (i > MAX) { | ||
setTimeout(cb, 10, null, []); | ||
} else { | ||
const array = []; | ||
const max = i + BATCH; | ||
for (; i < max; i++) { | ||
array.push(i); | ||
} | ||
setTimeout(cb, 10, null, array); | ||
} | ||
} | ||
|
||
readable.on('readable', () => { | ||
let data; | ||
console.log('readable emitted'); | ||
while (data = readable.read()) { | ||
console.log(data); | ||
} | ||
}); | ||
|
||
readable.on('end', () => { | ||
assert.strictEqual(i, (Math.floor(MAX / BATCH) + 1) * BATCH); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters