mirror of
https://github.com/nodejs/node.git
synced 2025-05-06 21:35:34 +00:00

There are places in the code base where setTimeout() or setInterval() are called with just a callback and no duration/interval. The timers module will use a value of `1` in that situation. An unspecified duration or interval can be confusing. Did the original author forget to provide a value? Did they intend to use setImmediate() or process.nextTick() instead of setTimeout()? And so on. This change provides a duration or interval of `1` to all calls in the codebase where it is missing. `parallel/test-timers.js` still tests the situation where `setTimeout()` and `setInterval()` are called with `undefined` and other non-numeric values for the duration/interval. PR-URL: https://github.com/nodejs/node/pull/9472 Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
30 lines
649 B
JavaScript
30 lines
649 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
|
|
// Make sure we don't miss the end event for paused 0-length streams
|
|
|
|
const Readable = require('stream').Readable;
|
|
const stream = new Readable();
|
|
let calledRead = false;
|
|
stream._read = function() {
|
|
assert(!calledRead);
|
|
calledRead = true;
|
|
this.push(null);
|
|
};
|
|
|
|
stream.on('data', function() {
|
|
throw new Error('should not ever get data');
|
|
});
|
|
stream.pause();
|
|
|
|
setTimeout(common.mustCall(function() {
|
|
stream.on('end', common.mustCall(function() {}));
|
|
stream.resume();
|
|
}), 1);
|
|
|
|
process.on('exit', function() {
|
|
assert(calledRead);
|
|
console.log('ok');
|
|
});
|