Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
http: agent use once helper
  • Loading branch information
ronag committed Apr 12, 2020
commit b0c8a22f88cde6d8fe5a12711c0e7c3f09df3e8f
10 changes: 4 additions & 6 deletions lib/_http_agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const {
ERR_INVALID_ARG_TYPE,
},
} = require('internal/errors');
const { once } = require('internal/util');

const kOnKeylog = Symbol('onkeylog');
// New Agent code.

Expand Down Expand Up @@ -268,12 +270,8 @@ Agent.prototype.createSocket = function createSocket(req, options, cb) {

debug('createConnection', name, options);
options.encoding = null;
let called = false;

const oncreate = (err, s) => {
if (called)
return;
called = true;
const oncreate = once((err, s) => {
if (err)
return cb(err);
if (!this.sockets[name]) {
Expand All @@ -283,7 +281,7 @@ Agent.prototype.createSocket = function createSocket(req, options, cb) {
debug('sockets', name, this.sockets[name].length);
installListeners(this, s, options);
cb(null, s);
};
});

const newSocket = this.createConnection(options, oncreate);
if (newSocket)
Expand Down