-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Track timers + display in status server to try to help diagnose stalls
Ref #99
- Loading branch information
1 parent
bb94c33
commit 92f5751
Showing
8 changed files
with
116 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
"use strict"; | ||
// wrapper around setTimeout to allow all timers to be tracked | ||
var timers = {}; | ||
var timerPos = 0; | ||
|
||
function TimerWrapper(label, callback, delay) { | ||
this.label = label; | ||
this.cb = callback; | ||
this._id = ++timerPos; | ||
this.delay = delay; | ||
this.start = Date.now(); | ||
this.timer = setTimeout(this._onTimeout.bind(this), delay); | ||
timers[this._id] = this; | ||
} | ||
TimerWrapper.prototype = { | ||
label: null, | ||
timer: null, | ||
start: 0, | ||
delay: 0, | ||
cb: null, | ||
onCancel: null, | ||
_id: 0, | ||
_onTimeout: function() { | ||
this._remove(); | ||
this.cb(); | ||
}, | ||
cancel: function() { | ||
if(this.timer) { | ||
clearTimeout(this.timer); | ||
this._remove(); | ||
if(this.onCancel) this.onCancel(); | ||
} | ||
}, | ||
_remove: function() { | ||
delete timers[this._id]; | ||
this.timer = null; | ||
} | ||
}; | ||
|
||
module.exports = function(label, callback, delay) { | ||
return new TimerWrapper(label, callback, delay); | ||
}; | ||
|
||
module.exports.all = function() { | ||
var ret = []; | ||
for(var id in timers) | ||
ret.push(timers[id]); | ||
return ret; | ||
}; | ||
|
||
module.exports.None = { | ||
label: null, | ||
cancel: function(){} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters