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 MylesBorins committed Jan 8, 2018
1 parent 134238c commit e5394e5
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/internal/http.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down

0 comments on commit e5394e5

Please sign in to comment.