mirror of
https://github.com/nodejs/node.git
synced 2025-05-06 20:08:02 +00:00

* use common.mustCall() as appropriate * eliminate exit handler * var -> const/let * provide duration for setInterval() PR-URL: https://github.com/nodejs/node/pull/10588 Reviewed-By: Italo A. Casas <me@italoacasas.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
31 lines
758 B
JavaScript
31 lines
758 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
|
|
const stream = require('stream');
|
|
const PassThrough = stream.PassThrough;
|
|
|
|
const src = new PassThrough({ objectMode: true });
|
|
const tx = new PassThrough({ objectMode: true });
|
|
const dest = new PassThrough({ objectMode: true });
|
|
|
|
const expect = [ -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ];
|
|
const results = [];
|
|
|
|
dest.on('data', common.mustCall(function(x) {
|
|
results.push(x);
|
|
}, expect.length));
|
|
|
|
src.pipe(tx).pipe(dest);
|
|
|
|
let i = -1;
|
|
const int = setInterval(common.mustCall(function() {
|
|
if (results.length === expect.length) {
|
|
src.end();
|
|
clearInterval(int);
|
|
assert.deepStrictEqual(results, expect);
|
|
} else {
|
|
src.write(i++);
|
|
}
|
|
}, expect.length + 1), 1);
|