Skip to content

Commit

Permalink
Merge e11b78a into afd4710
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleytodd committed Apr 1, 2021
2 parents afd4710 + e11b78a commit 897d7b1
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function Reissue(opts) {
assert.optionalObject(opts.context, 'context');
assert.optionalArray(opts.args, 'args');
assert.optionalNumber(opts.timeout, 'timeout');
assert.optionalBool(opts.unref, 'unref');

// assert options of different types
const typeofInterval = typeof opts.interval;
Expand Down Expand Up @@ -93,6 +94,13 @@ function Reissue(opts) {
*/
self._timeoutMs = opts.timeout || null;

/**
* unref the timeout
* @private
* @type {Boolean}
*/
self._unref = opts.unref;

//--------------------------------------------------------------------------
// internal properties
//--------------------------------------------------------------------------
Expand Down Expand Up @@ -173,6 +181,9 @@ Reissue.prototype._execute = function _execute() {
bind(self._onTimeout, self),
self._timeoutMs
);
if (self._unref) {
self._timeoutHandlerId.unref();
}
}
};

Expand Down Expand Up @@ -228,6 +239,9 @@ Reissue.prototype._done = function _done(err) {
self._nextHandlerId = setTimeout(function _nextInvocation() {
self._execute();
}, timeToInvocation);
if (self._unref) {
self._nextHandlerId.unref();
}
}
}
};
Expand Down Expand Up @@ -309,6 +323,9 @@ Reissue.prototype.start = function start(delay) {
self._nextHandlerId = setTimeout(function _nextInvocation() {
self._execute();
}, delay);
if (self._unref) {
self._nextHandlerId.unref();
}
} else {
self._execute();
}
Expand Down

0 comments on commit 897d7b1

Please sign in to comment.