mirror of https://github.com/lukechilds/node.git
Browse Source
* 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>v6
Rich Trott
8 years ago
1 changed files with 14 additions and 17 deletions
@ -1,33 +1,30 @@ |
|||||
'use strict'; |
'use strict'; |
||||
require('../common'); |
const common = require('../common'); |
||||
const assert = require('assert'); |
const assert = require('assert'); |
||||
|
|
||||
const stream = require('stream'); |
const stream = require('stream'); |
||||
var PassThrough = stream.PassThrough; |
const PassThrough = stream.PassThrough; |
||||
|
|
||||
var src = new PassThrough({ objectMode: true }); |
const src = new PassThrough({ objectMode: true }); |
||||
var tx = new PassThrough({ objectMode: true }); |
const tx = new PassThrough({ objectMode: true }); |
||||
var dest = new PassThrough({ objectMode: true }); |
const dest = new PassThrough({ objectMode: true }); |
||||
|
|
||||
var expect = [ -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]; |
const expect = [ -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]; |
||||
var results = []; |
const results = []; |
||||
process.on('exit', function() { |
|
||||
assert.deepStrictEqual(results, expect); |
|
||||
console.log('ok'); |
|
||||
}); |
|
||||
|
|
||||
dest.on('data', function(x) { |
dest.on('data', common.mustCall(function(x) { |
||||
results.push(x); |
results.push(x); |
||||
}); |
}, expect.length)); |
||||
|
|
||||
src.pipe(tx).pipe(dest); |
src.pipe(tx).pipe(dest); |
||||
|
|
||||
var i = -1; |
let i = -1; |
||||
var int = setInterval(function() { |
const int = setInterval(common.mustCall(function() { |
||||
if (i > 10) { |
if (results.length === expect.length) { |
||||
src.end(); |
src.end(); |
||||
clearInterval(int); |
clearInterval(int); |
||||
|
assert.deepStrictEqual(results, expect); |
||||
} else { |
} else { |
||||
src.write(i++); |
src.write(i++); |
||||
} |
} |
||||
}); |
}, expect.length + 1), 1); |
||||
|
Loading…
Reference in new issue