Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bind the step function to the active domain (if present) #197

Merged
merged 3 commits into from
May 26, 2015
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,8 @@
runtime.async = function(innerFn, outerFn, self, tryLocsList) {
return new Promise(function(resolve, reject) {
var generator = wrap(innerFn, outerFn, self, tryLocsList);
var callNext = step.bind(generator, "next");
var callThrow = step.bind(generator, "throw");

function step(method, arg) {
var step = function(method, arg) {
var record = tryCatch(generator[method], generator, arg);
if (record.type === "throw") {
reject(record.arg);
Expand All @@ -121,8 +119,15 @@
} else {
Promise.resolve(info.value).then(callNext, callThrow);
}
};

if (process && process.domain) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will still throw in browsers since process wont be defined. You'll need to do typeof process !== "undefined".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not ensure that process is declared. It only ensures that process does not have a falsy value. It will still throw if it is not declared.typeof is pretty much the only way to go here.

step = process.domain.bind(step);
}

var callNext = step.bind(generator, "next");
var callThrow = step.bind(generator, "throw");

callNext();
});
};
Expand Down