Skip to content

Commit

Permalink
Merge pull request request#1168 from seanstrom/support/use-setimmedia…
Browse files Browse the repository at this point in the history
…te-when-available

create a detach helper and use detach helper in replace of nextTick
  • Loading branch information
FredKSchott committed Oct 15, 2014
2 parents f5a25f1 + a1d3700 commit 53642db
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
8 changes: 8 additions & 0 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ var extend = require('util')._extend
, jsonSafeStringify = require('json-stringify-safe')
, crypto = require('crypto')

function deferMethod() {
if(typeof setImmediate === 'undefined') {
return process.nextTick
}

return setImmediate
}

function constructObject(initialObject) {
initialObject = initialObject || {}
Expand Down Expand Up @@ -79,3 +86,4 @@ exports.safeStringify = safeStringify
exports.md5 = md5
exports.isReadStream = isReadStream
exports.toBase64 = toBase64
exports.defer = deferMethod()
11 changes: 3 additions & 8 deletions request.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var optional = require('./lib/optional')
, md5 = helpers.md5
, isReadStream = helpers.isReadStream
, toBase64 = helpers.toBase64
, defer = helpers.defer
, bl = require('bl')
, oauth = optional('oauth-sign')
, hawk = optional('hawk')
Expand Down Expand Up @@ -654,7 +655,7 @@ Request.prototype.init = function (options) {
// })
})

process.nextTick(function () {
defer(function () {
if (self._aborted) {
return
}
Expand Down Expand Up @@ -761,13 +762,7 @@ Request.prototype.init = function (options) {
}

function wait_for_socket_response(){
var detach
if(typeof setImmediate === 'undefined') {
detach = process.nextTick
} else {
detach = setImmediate
}
detach(function(){
defer(function(){
// counter to prevent infinite blocking waiting for an open socket to be found.
response_counter++
var trying = false
Expand Down

0 comments on commit 53642db

Please sign in to comment.