@risingstack/trace
Version:
RisingStack Trace Node.js collector
36 lines (30 loc) • 718 B
JavaScript
function Timer (task, interval) {
this._handle = undefined
this.task = task
this._interval = interval
}
Timer.prototype.start = function (interval) {
if (interval != null) {
this._interval = interval
}
if (this._handle == null) {
this._handle = setInterval(this.task, this._interval)
}
}
Timer.prototype.end = function () {
if (this._handle != null) {
clearInterval(this._handle)
this._handle = undefined
}
}
Timer.prototype.restart = function (interval) {
if (interval != null) {
this._interval = interval
}
if (this._handle != null) {
clearInterval(this._handle)
this._handle = setInterval(this.task, this._interval)
}
}
module.exports = Timer