Permalink
Browse files

lazily start timeout intervals

  • Loading branch information...
1 parent c740019 commit d3b218789f71b59350092bb1d98dfff1c0b42228 @dannycoates committed Jun 7, 2012
Showing with 9 additions and 2 deletions.
  1. +9 −2 lib/endpoint.js
View
@@ -3,7 +3,7 @@ var Stream = require('stream')
module.exports = function (inherits, EventEmitter) {
var MAX_COUNT = Math.pow(2, 31) // largest smi value
var clock = Date.now()
- setInterval(function () { clock = Date.now() }, 10)
+ var clockInterval = null
function noop() { return false }
//
@@ -42,7 +42,14 @@ module.exports = function (inherits, EventEmitter) {
this.timeout = options.timeout || (60 * 1000)
this.resolution = options.resolution || 1000
- this.timeoutInterval = setInterval(this.checkTimeouts.bind(this), this.resolution)
+
+ this.timeoutInterval = (this.resolution > 0) ?
+ setInterval(this.checkTimeouts.bind(this), this.resolution) :
+ null
+
+ if (!clockInterval) {
+ clockInterval = setInterval(function () { clock = Date.now() }, 10)
+ }
this.ping()
}

0 comments on commit d3b2187

Please sign in to comment.