Skip to content

Commit

Permalink
Make sure Q is in a real Node environment
Browse files Browse the repository at this point in the history
This adds an additional check to ensure that the process global Q looks for is closer to the global that Nodejs environments expose. This is in light of updates to `node-process` a process shim used by Browserify:

https://github.com/defunctzombie/node-process/

This library no longer uses `setImmediate` if it is available, it uses `setTimeout` out of the box. Because Browserify is getting so popular as a moduling system, I think it is wise to add this check, so Browserify user's get all the extra `setImmediate` juice they possibly can.
  • Loading branch information
kahnvex committed Apr 23, 2015
1 parent ed721ca commit b57834b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion q.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,15 @@ var nextTick =(function () {
}
};

if (typeof process !== "undefined" && process.nextTick) {
if (typeof process === "object" && (process + '') === '[object process]' &&
process.nextTick) {
// Node.js before 0.9. Note that some fake-Node environments, like the
// Mocha test runner, introduce a `process` global without a `nextTick`.
// In addition, some fake-Node environments like browserify expose a
// `process.nexTick` function that uses `setTimeout`. In this case we'd
// much rather use `setImmediate` because it is faster. To ensure we are
// in a real Node environment, doing process + '' should be
// '[object process]'.
isNodeJS = true;

requestTick = function () {
Expand Down

0 comments on commit b57834b

Please sign in to comment.