timeout-refresh
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -8,2 +8,3 @@ module.exports = Timeout | ||
this.context = ctx || null | ||
this.called = false | ||
this._timeout = setTimeout(call, ms, this) | ||
@@ -13,2 +14,3 @@ } | ||
Timeout.prototype.refresh = function () { | ||
if (this.called || this.ontimeout === null) return | ||
clearTimeout(this._timeout) | ||
@@ -24,3 +26,4 @@ this._timeout = setTimeout(call, this.ms, this) | ||
function call (self) { | ||
self.called = true | ||
self.ontimeout.call(self.context) | ||
} |
{ | ||
"name": "timeout-refresh", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Efficiently refresh a timer", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -8,2 +8,3 @@ module.exports = Timer | ||
this.context = ctx || null | ||
this.called = false | ||
this._timeout = setTimeout(call, ms, this) | ||
@@ -14,2 +15,3 @@ this._timeout.unref() | ||
Timer.prototype.refresh = function () { | ||
if (this.called || this.ontimeout === null) return | ||
this._timeout.refresh() | ||
@@ -24,3 +26,4 @@ } | ||
function call (self) { | ||
self.called = true | ||
self.ontimeout.call(self.context) | ||
} |
17
test.js
@@ -53,2 +53,19 @@ const tape = require('tape') | ||
}) | ||
tape(prefix + 'cannot be refreshed after call', function (t) { | ||
t.plan(2) | ||
var timedout = false | ||
const to = timeout(50, function () { | ||
t.notOk(timedout, 'did not already timeout') | ||
t.pass('should be destroyed') | ||
to.refresh() | ||
timedout = true | ||
}) | ||
setTimeout(function () { | ||
t.end() | ||
}, 500) | ||
}) | ||
} |
@@ -14,2 +14,3 @@ var timers = require('timers') | ||
this.context = ctx || null | ||
this.called = false | ||
enroll(this, ms) | ||
@@ -20,2 +21,3 @@ active(this) | ||
Timeout.prototype._onTimeout = function () { | ||
this.called = true | ||
this.ontimeout.call(this.context) | ||
@@ -25,2 +27,3 @@ } | ||
Timeout.prototype.refresh = function () { | ||
if (this.called || this.ontimeout === null) return | ||
active(this) | ||
@@ -27,0 +30,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6598
149