Skip to content

Commit

Permalink
http: convert utcDate to use setTimeout
Browse files Browse the repository at this point in the history
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 28, 2017
1 parent 8578fe2 commit f94eec0
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/internal/http.js
@@ -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');
Expand Down

0 comments on commit f94eec0

Please sign in to comment.