Skip to content
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: expose timer classes #8192

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ exports.clearInterval = function(timer) {
};


exports.Timeout = Timeout;
function Timeout(after) {
this._called = false;
this._idleTimeout = after;
Expand Down Expand Up @@ -585,6 +586,7 @@ function runCallback(timer) {
}


exports.Immediate = Immediate;
function Immediate() {
// assigning the callback here can cause optimize/deoptimize thrashing
// so have caller annotate the object (node v6.0.0, v8 5.0.71.35)
Expand Down
18 changes: 18 additions & 0 deletions test/parallel/test-timers-classes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';
require('../common');
const assert = require('assert');

const timers = require('timers');

const immediate = setImmediate(() => {});
const timeout = setTimeout(() => {}, 0);
const interval = setInterval(() => {}, 0);

assert(immediate instanceof timers.Immediate);
assert(timeout instanceof timers.Timeout);
assert(interval instanceof timers.Timeout);

// Clean up
clearImmediate(immediate);
clearTimeout(timeout);
clearInterval(interval);