Skip to content

Commit

Permalink
Merge 8c7f6d0 into 8162961
Browse files Browse the repository at this point in the history
  • Loading branch information
turt2live committed Oct 30, 2018
2 parents 8162961 + 8c7f6d0 commit e189cc0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
12 changes: 9 additions & 3 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ var jsonSafeStringify = require('json-stringify-safe')
var crypto = require('crypto')
var Buffer = require('safe-buffer').Buffer

var defer = typeof setImmediate === 'undefined'
? process.nextTick
: setImmediate
function defer (f, runImmediate) {
if (runImmediate) {
f()
} else if (typeof setImmediate === 'undefined') {
process.nextTick(f)
} else {
setImmediate(f)
}
}

function paramsHaveRequestBody (params) {
return (
Expand Down
2 changes: 1 addition & 1 deletion request.js
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ Request.prototype.init = function (options) {
}

self.ntick = true
})
}, options.runImmediate)
}

Request.prototype.getNewAgent = function () {
Expand Down
12 changes: 12 additions & 0 deletions tests/browser/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,15 @@ tape('succeeds on valid URLs (with https and CORS)', function (t) {
t.end()
})
})

tape('supports runImmediate', function (t) {
t.plan(1)
request({
uri: __karma__.config.requestTestUrl, // eslint-disable-line no-undef
withCredentials: false,
runImmediate: true
}, function (_, response) {
t.equal(response.statusCode, 200)
t.end()
})
})

0 comments on commit e189cc0

Please sign in to comment.