-
Notifications
You must be signed in to change notification settings - Fork 30.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
timers: fix regression with clearImmediate() #9086
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict'; | ||
require('../common'); | ||
const assert = require('assert'); | ||
|
||
const N = 3; | ||
var count = 0; | ||
function next() { | ||
const immediate = setImmediate(function() { | ||
clearImmediate(immediate); | ||
++count; | ||
}); | ||
} | ||
for (var i = 0; i < N; ++i) | ||
next(); | ||
|
||
process.on('exit', () => { | ||
assert.strictEqual(count, N, `Expected ${N} immediate callback executions`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Maybe even go a bit further? 'use strict';
const common = require('../common');
function next() {
const immediate = setImmediate(common.mustCall(function callback() {
clearImmediate(immediate);
}));
}
for (var i = 0; i < 3; ++i)
next(); One benefit is that we don't lose the information of what There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't understand what you mean here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the way the test is written now, when the test fails, we get:
So, we were expecting 3, but we got some other number. How many? 0? 1? 2? 4? So I was looking at how to work
And the test is a compact 10 lines to boot. (As usual: It's a nit, so you know, ignore my suggestion if you don't like it.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Fishrock123 Is this ok with you, since you previously requested that a custom assertion message be added? |
||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kept with
var
because it is still used throughout timers.js.