Permalink
Browse files

http: convert utcDate to use setTimeout

A sort-of follow-up to #17704, this
removes the last internal use of enroll().

PR-URL: #17800
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information...
Fishrock123 authored and BridgeAR committed Dec 21, 2017
1 parent 8578fe2 commit f94eec0218419a639c6c0019d8e4a48a894f7aff
Showing with 6 additions and 5 deletions.
  1. +6 −5 lib/internal/http.js
View
@@ -1,20 +1,21 @@
'use strict';
const timers = require('timers');
const { setUnrefTimeout } = require('internal/timers');
var dateCache;
function utcDate() {
if (!dateCache) {
const d = new Date();
dateCache = d.toUTCString();
timers.enroll(utcDate, 1000 - d.getMilliseconds());
timers._unrefActive(utcDate);
setUnrefTimeout(resetCache, 1000 - d.getMilliseconds());
}
return dateCache;
}
utcDate._onTimeout = function() {
function resetCache() {
dateCache = undefined;
};
}
function ondrain() {
if (this._httpMessage) this._httpMessage.emit('drain');

0 comments on commit f94eec0

Please sign in to comment.