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

Improving code readability on lib/_http_agent.js #83

Closed
wants to merge 2 commits into from
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
Fixing typos
  • Loading branch information
imjacobclark committed Dec 5, 2014
commit de1a4b0f50c2bd74197e8defe5e3fe4370295632
16 changes: 8 additions & 8 deletions lib/_http_agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ function Agent(options) {

var freeSockets = self.freeSockets[name];
var totalSocketLength = freeSockets ? freeSockets.length : 0;
var socketsAvaliable = totalSocketLength < this.maxSockets || totalSocketLength >= self.maxFreeSockets;
var socketsAvailable = totalSocketLength < this.maxSockets || totalSocketLength >= self.maxFreeSockets;

if (self.sockets[name])
totalSocketLength += self.sockets[name].length;

if (socketsAvaliable) {
if (socketsAvailable) {
self.removeSocket(socket, options);
socket.destroy();
} else {
Expand Down Expand Up @@ -147,11 +147,11 @@ Agent.prototype.addRequest = function(req, options) {
this.sockets[name] = [];
}

var avaliableFreeSockets = this.freeSockets[name] ? this.freeSockets[name].length : 0;
var totalSocketLength = avaliableFreeSockets + this.sockets[name].length;
var socketsAvaliable = totalSocketLength < this.maxSockets;
var availableFreeSockets = this.freeSockets[name] ? this.freeSockets[name].length : 0;
var totalSocketLength = availableFreeSockets + this.sockets[name].length;
var socketsAvailable = totalSocketLength < this.maxSockets;

if (avaliableFreeSockets) {
if (availableFreeSockets) {
// we have a free socket, so use that.
var socket = this.freeSockets[name].shift();
debug('have free socket');
Expand All @@ -165,8 +165,8 @@ Agent.prototype.addRequest = function(req, options) {
socket.ref();
req.onSocket(socket);
this.sockets[name].push(socket);
} else if (socketsAvaliable) {
debug('call onSocket', totalSocketLength, avaliableFreeSockets);
} else if (socketsAvailable) {
debug('call onSocket', totalSocketLength, availableFreeSockets);
req.onSocket(this.createSocket(req, options));
} else {
debug('wait for socket');
Expand Down