Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http: convert utcDate to use setTimeout #17800

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(timeout, 1000 - d.getMilliseconds());
}
return dateCache;
}
utcDate._onTimeout = function() {

function timeout() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe call this function resetCache or sth like that, timeout doesn't really say what it's doing...

dateCache = undefined;
};
}

function ondrain() {
if (this._httpMessage) this._httpMessage.emit('drain');
Expand Down