Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cache the result of Date.now() in a variable

  • Loading branch information...
commit d2cae24288d838abfb67f53f6e659e6533925f20 1 parent f53e238
@bnoordhuis bnoordhuis authored wicked committed
Showing with 3 additions and 2 deletions.
  1. +3 −2 lib/timers.js
View
5 lib/timers.js
@@ -254,8 +254,9 @@ var Timeout = function(after) {
Timeout.prototype.unref = function() {
if (!this._handle) {
- if (!this._idleStart) this._idleStart = Date.now();
- var delay = this._idleStart + this._idleTimeout - Date.now();
+ var now = Date.now();
+ if (!this._idleStart) this._idleStart = now;
+ var delay = this._idleStart + this._idleTimeout - now;
if (delay < 0) delay = 0;
exports.unenroll(this);
this._handle = new Timer();

2 comments on commit d2cae24

@olecom
  • var delay = Date.now();
  • if (!this._idleStart) this._idleStart = delay;
  • delay = this._idleStart + this._idleTimeout - delay;

Why not?

@AlexeyKupershtokh

maybe because this is semantically wrong? :)

Please sign in to comment.
Something went wrong with that request. Please try again.