From 10f36d7392f9070f4af75ae757b61b56d4da3294 Mon Sep 17 00:00:00 2001 From: Ryan Leckey Date: Sun, 3 May 2015 19:21:35 -0700 Subject: [PATCH] Bind the step function to the active domain (if present) --- runtime.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/runtime.js b/runtime.js index 186a09f12..017f8e51f 100644 --- a/runtime.js +++ b/runtime.js @@ -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); @@ -121,8 +119,15 @@ } else { Promise.resolve(info.value).then(callNext, callThrow); } + }; + + if (process.domain) { + step = process.domain.bind(step); } + var callNext = step.bind(generator, "next"); + var callThrow = step.bind(generator, "throw"); + callNext(); }); };