Skip to content

Commit

Permalink
cache http agents (#1682)
Browse files Browse the repository at this point in the history
  • Loading branch information
npoltorapavlo authored and Michael Fiess committed Jan 14, 2019
1 parent 2252f37 commit d0efbbb
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions examples/pxScene2d/src/rcvrcore/http_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,11 @@ function Request(moduleName, appSceneContext, options, callback) {
// convert a dummy Agent into a real one
if (options.agent instanceof Agent) {
var agentObj = options.agent;
var newAgent = isV8 ? null : new module.Agent(agentObj.options);
options.agent = newAgent;
var newAgent = isV8 ? null : (AgentCache[agentObj.uid] || new module.Agent(agentObj.options));
options.agent = AgentCache[agentObj.uid] = newAgent;
agentObj.once('destroy', function () {
if (newAgent) {
log.message(4, 'destroying the agent');
newAgent.destroy.apply(newAgent, arguments);
}
});
Expand Down Expand Up @@ -305,8 +306,11 @@ Response.prototype.blocked = false;
function Agent(options) {
EventEmitter.call(this);

this.setMaxListeners(Infinity);

log.message(4, "creating a new agent");
this.options = options;
this.uid = Math.floor(100000 + Math.random() * 900000);

var self = this;
this.destroy = function () {
Expand All @@ -318,6 +322,8 @@ function Agent(options) {
Agent.prototype = Object.create(EventEmitter.prototype);
Agent.prototype.constructor = Agent;

var AgentCache = {};

function Utils() {
}

Expand Down

0 comments on commit d0efbbb

Please sign in to comment.