Skip to content
This repository has been archived by the owner on Feb 1, 2025. It is now read-only.

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

Merged
merged 3 commits into from
May 26, 2015
Merged
Changes from all 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 (typeof process !== "undefined" && process.domain) {
step = process.domain.bind(step);
}

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

callNext();
});
};
Expand Down