From f7fe35fce2cf9ee6d7fb78f5c00bba962a5e1491 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Wed, 17 Aug 2016 18:49:05 +0300 Subject: [PATCH] fix for promises --- index.js | 11 +++-------- package.json | 2 +- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 8ad9e7a..48dac11 100644 --- a/index.js +++ b/index.js @@ -33,7 +33,8 @@ function runThread(generator, onsuccess, onerror) var thread = function() { thread._current = null; - continueThread.apply(thread, arguments); + // pass parameters as yield result + callGen(thread, 'next', Array.prototype.slice.call(arguments, 0)); }; thread._gen = generator.next ? generator : generator(); thread._finishThrottleQueue = finishThrottleQueue.bind(thread); @@ -44,12 +45,6 @@ function runThread(generator, onsuccess, onerror) return thread; } -function continueThread() -{ - // pass parameters as yield result - callGen(this, 'next', Array.prototype.slice.call(arguments, 0)); -} - function getStack(fn) { return fn._stack.replace(/Error[\s\S]*at.*(exports\.(cb|ef|errorfirst)|Function\.(errorFirst|threadCallback)).*/, ''); @@ -106,7 +101,7 @@ 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(current); + var cb = threadCallback.call(thread); v.value.then(cb, function(error) { callGen(thread, 'throw', error); diff --git a/package.json b/package.json index cdf0e1c..463b493 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gen-thread", - "version": "1.0.0", + "version": "1.0.1", "author": { "name": "Vitaliy Filippov", "email": "vitalif@yourcmc.ru"