http: convert utcDate to use setTimeout

A sort-of follow-up to https://github.com/nodejs/node/pull/17704, this
removes the last internal use of enroll().

PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Jeremiah Senkpiel 2017-12-20 21:50:19 -05:00 committed by Ruben Bridgewater
parent 8578fe22a9
commit f94eec0218
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762

View File

@ -1,20 +1,21 @@
'use strict'; 'use strict';
const timers = require('timers'); const { setUnrefTimeout } = require('internal/timers');
var dateCache; var dateCache;
function utcDate() { function utcDate() {
if (!dateCache) { if (!dateCache) {
const d = new Date(); const d = new Date();
dateCache = d.toUTCString(); dateCache = d.toUTCString();
timers.enroll(utcDate, 1000 - d.getMilliseconds());
timers._unrefActive(utcDate); setUnrefTimeout(resetCache, 1000 - d.getMilliseconds());
} }
return dateCache; return dateCache;
} }
utcDate._onTimeout = function() {
function resetCache() {
dateCache = undefined; dateCache = undefined;
}; }
function ondrain() { function ondrain() {
if (this._httpMessage) this._httpMessage.emit('drain'); if (this._httpMessage) this._httpMessage.emit('drain');