From 9510901f3f3be7afa60397e43dceb2769f14b51f Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Tue, 23 Aug 2016 19:04:24 +0300 Subject: [PATCH] Prevent Promise from intercepting our exceptions --- index.js | 9 ++++++--- package.json | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 48dac11..433f694 100644 --- a/index.js +++ b/index.js @@ -101,10 +101,13 @@ function callGen(thread, method, arg) else if (typeof v.value == 'object' && v.value.then) { // check if v.value is a Promise - var cb = threadCallback.call(thread); - v.value.then(cb, function(error) + v.value.then(function(value) { - callGen(thread, 'throw', error); + // use process.nextTick so Promise does not intercept our exceptions + process.nextTick(function() { callGen(thread, 'next', value); }); + }, function(error) + { + process.nextTick(function() { callGen(thread, 'throw', error); }); }); } } diff --git a/package.json b/package.json index 463b493..28574ef 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gen-thread", - "version": "1.0.1", + "version": "1.0.2", "author": { "name": "Vitaliy Filippov", "email": "vitalif@yourcmc.ru"