Skip to content
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
11 changes: 10 additions & 1 deletion lib/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,14 @@ const Timeout = function(after) {
this._repeat = null;
};


function unrefdHandle() {
this.owner._onTimeout();
if (!this.owner._repeat)
this.owner.close();
}


Timeout.prototype.unref = function() {
if (this._handle) {
this._handle.unref();
Expand All @@ -315,7 +323,8 @@ Timeout.prototype.unref = function() {
if (this._called && !this._repeat) return;

this._handle = new Timer();
this._handle[kOnTimeout] = this._onTimeout;
this._handle.owner = this;
this._handle[kOnTimeout] = unrefdHandle;
this._handle.start(delay, 0);
this._handle.domain = this.domain;
this._handle.unref();
Expand Down
18 changes: 18 additions & 0 deletions test/parallel/test-timers-unrefd-interval-still-fires.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* This test is a regression test for joyent/node#8900.
*/
var assert = require('assert');

var N = 5;
var nbIntervalFired = 0;
var timer = setInterval(function() {
++nbIntervalFired;
if (nbIntervalFired === N)
clearInterval(timer);
}, 1);

timer.unref();

setTimeout(function onTimeout() {
assert.strictEqual(nbIntervalFired, N);
}, 100);