From 45ac376f749be8bdd50c57a6008a556d1ad2ea30 Mon Sep 17 00:00:00 2001 From: seanstrom Date: Tue, 14 Oct 2014 19:42:01 -0700 Subject: [PATCH 1/2] create a detach helper and use detach helper in replace of process.nextTick --- lib/helpers.js | 8 ++++++++ request.js | 9 ++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/helpers.js b/lib/helpers.js index 699d795cd..e2de7847f 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -4,6 +4,13 @@ var extend = require('util')._extend , jsonSafeStringify = require('json-stringify-safe') , crypto = require('crypto') +function detachMethod() { + if(typeof setImmediate === 'undefined') { + return process.nextTick + } + + return setImmediate +} function constructObject(initialObject) { initialObject = initialObject || {} @@ -79,3 +86,4 @@ exports.safeStringify = safeStringify exports.md5 = md5 exports.isReadStream = isReadStream exports.toBase64 = toBase64 +exports.detach = detachMethod() diff --git a/request.js b/request.js index b434655ee..f72fdf165 100644 --- a/request.js +++ b/request.js @@ -14,6 +14,7 @@ var optional = require('./lib/optional') , md5 = helpers.md5 , isReadStream = helpers.isReadStream , toBase64 = helpers.toBase64 + , detach = helpers.detach , bl = require('bl') , oauth = optional('oauth-sign') , hawk = optional('hawk') @@ -654,7 +655,7 @@ Request.prototype.init = function (options) { // }) }) - process.nextTick(function () { + detach(function () { if (self._aborted) { return } @@ -761,12 +762,6 @@ Request.prototype.init = function (options) { } function wait_for_socket_response(){ - var detach - if(typeof setImmediate === 'undefined') { - detach = process.nextTick - } else { - detach = setImmediate - } detach(function(){ // counter to prevent infinite blocking waiting for an open socket to be found. response_counter++ From a1d370031f894758ed9b64fe8da5ce171729f03d Mon Sep 17 00:00:00 2001 From: seanstrom Date: Wed, 15 Oct 2014 14:29:57 -0700 Subject: [PATCH 2/2] change detach to defer --- lib/helpers.js | 4 ++-- request.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/helpers.js b/lib/helpers.js index e2de7847f..fa5712ffb 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -4,7 +4,7 @@ var extend = require('util')._extend , jsonSafeStringify = require('json-stringify-safe') , crypto = require('crypto') -function detachMethod() { +function deferMethod() { if(typeof setImmediate === 'undefined') { return process.nextTick } @@ -86,4 +86,4 @@ exports.safeStringify = safeStringify exports.md5 = md5 exports.isReadStream = isReadStream exports.toBase64 = toBase64 -exports.detach = detachMethod() +exports.defer = deferMethod() diff --git a/request.js b/request.js index f72fdf165..48e8044b6 100644 --- a/request.js +++ b/request.js @@ -14,7 +14,7 @@ var optional = require('./lib/optional') , md5 = helpers.md5 , isReadStream = helpers.isReadStream , toBase64 = helpers.toBase64 - , detach = helpers.detach + , defer = helpers.defer , bl = require('bl') , oauth = optional('oauth-sign') , hawk = optional('hawk') @@ -655,7 +655,7 @@ Request.prototype.init = function (options) { // }) }) - detach(function () { + defer(function () { if (self._aborted) { return } @@ -762,7 +762,7 @@ Request.prototype.init = function (options) { } function wait_for_socket_response(){ - detach(function(){ + defer(function(){ // counter to prevent infinite blocking waiting for an open socket to be found. response_counter++ var trying = false