node/lib/internal/http.js
Jeremiah Senkpiel f94eec0218
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>
2017-12-29 00:08:54 +01:00

29 lines
495 B
JavaScript

'use strict';
const { setUnrefTimeout } = require('internal/timers');
var dateCache;
function utcDate() {
if (!dateCache) {
const d = new Date();
dateCache = d.toUTCString();
setUnrefTimeout(resetCache, 1000 - d.getMilliseconds());
}
return dateCache;
}
function resetCache() {
dateCache = undefined;
}
function ondrain() {
if (this._httpMessage) this._httpMessage.emit('drain');
}
module.exports = {
outHeadersKey: Symbol('outHeadersKey'),
ondrain,
utcDate
};