if (domain)
domain.enter();
threw = true;
+ first._called = true;
first._onTimeout();
if (domain)
domain.exit();
const Timeout = function(after) {
+ this._called = false;
this._idleTimeout = after;
this._idlePrev = this;
this._idleNext = this;
var delay = this._idleStart + this._idleTimeout - now;
if (delay < 0) delay = 0;
exports.unenroll(this);
+
+ // Prevent running cb again when unref() is called during the same cb
+ if (this._called && !this._repeat) return;
+
this._handle = new Timer();
this._handle[kOnTimeout] = this._onTimeout;
this._handle.start(delay, 0);
if (domain) domain.enter();
threw = true;
debug('unreftimer firing timeout');
+ first._called = true;
first._onTimeout();
threw = false;
if (domain)
timeout_fired = false,
unref_interval = false,
unref_timer = false,
+ unref_callbacks = 0,
interval, check_unref, checks = 0;
var LONG_TIME = 10 * 1000;
checks += 1;
}, 100);
+setTimeout(function() {
+ unref_callbacks++;
+ this.unref();
+}, SHORT_TIME);
+
+// Should not timeout the test
+setInterval(function() {
+ this.unref();
+}, SHORT_TIME);
+
// Should not assert on args.Holder()->InternalFieldCount() > 0. See #4261.
(function() {
var t = setInterval(function() {}, 1);
assert.strictEqual(timeout_fired, false, 'Timeout should not fire');
assert.strictEqual(unref_timer, true, 'An unrefd timeout should still fire');
assert.strictEqual(unref_interval, true, 'An unrefd interval should still fire');
+ assert.strictEqual(unref_callbacks, 1, 'Callback should only run once');
});