Comparing version 1.0.2 to 1.1.0
@@ -47,6 +47,6 @@ /* | ||
module.exports = Hub = function () { | ||
var hub, logPendingRequests, setupConnectTimeout; | ||
var hub, logPendingRequests, setupCompletionTimeout, setupTimeouts; | ||
hub = new EventEmitter; | ||
hub.fetch = function (options, cb) { | ||
var fetchId, fetchStart, hubHeaders, req, responseData; | ||
var completionTimeoutInterval, connectTimeoutInterval, fetchId, fetchStart, hubHeaders, req, responseData; | ||
fetchStart = microtime.nowDouble(); | ||
@@ -118,3 +118,5 @@ fetchId = generateUUID(); | ||
}); | ||
setupConnectTimeout(null != options.connectTimeout ? options.connectTimeout : Hub.connectTimeout, req, responseData); | ||
connectTimeoutInterval = null != options.connectTimeout ? options.connectTimeout : Hub.connectTimeout; | ||
completionTimeoutInterval = options.completionTimeout; | ||
setupTimeouts(connectTimeoutInterval, completionTimeoutInterval, req, responseData); | ||
return req; | ||
@@ -144,3 +146,3 @@ }; | ||
}; | ||
setupConnectTimeout = function (connectTimeoutInterval, request, responseData) { | ||
setupTimeouts = function (connectTimeoutInterval, completionTimeoutInterval, request, responseData) { | ||
return request.on('request', function (req) { | ||
@@ -164,3 +166,4 @@ return req.on('socket', function (socket) { | ||
clearTimeout(connectTimeout); | ||
return connectTimeout = null; | ||
connectTimeout = null; | ||
return setupCompletionTimeout(completionTimeoutInterval, req, responseData); | ||
}; | ||
@@ -173,2 +176,25 @@ connectingSocket = null != socket.socket ? socket.socket : socket; | ||
}; | ||
setupCompletionTimeout = function (completionTimeoutInterval, req, responseData) { | ||
var completionSuccessful, completionTimedOut, completionTimeout; | ||
if (!completionTimeoutInterval) | ||
return; | ||
completionTimeout = void 0; | ||
completionTimedOut = function () { | ||
var err; | ||
req.abort(); | ||
responseData.completionDuration = microtime.nowDouble() - responseData.connectDuration; | ||
err = new Error('ETIMEDOUT'); | ||
err.code = 'ETIMEDOUT'; | ||
err.message = 'Response timed out after ' + completionTimeoutInterval + 'ms'; | ||
err.responseData = responseData; | ||
return req.emit('error', err); | ||
}; | ||
completionSuccessful = function () { | ||
responseData.completionDuration = microtime.nowDouble() - responseData.connectDuration; | ||
clearTimeout(completionTimeout); | ||
return completionTimeout = null; | ||
}; | ||
req.on('complete', completionSuccessful); | ||
return completionTimeout = setTimeout(completionTimedOut, completionTimeoutInterval); | ||
}; | ||
return hub; | ||
@@ -175,0 +201,0 @@ }; |
{ | ||
"name": "gofer", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "A general purpose service client library for node.js", | ||
@@ -5,0 +5,0 @@ "main": "lib/gofer.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
46430
619
2