fix for promises
parent
c4c935bbc1
commit
f7fe35fce2
11
index.js
11
index.js
|
@ -33,7 +33,8 @@ function runThread(generator, onsuccess, onerror)
|
||||||
var thread = function()
|
var thread = function()
|
||||||
{
|
{
|
||||||
thread._current = null;
|
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._gen = generator.next ? generator : generator();
|
||||||
thread._finishThrottleQueue = finishThrottleQueue.bind(thread);
|
thread._finishThrottleQueue = finishThrottleQueue.bind(thread);
|
||||||
|
@ -44,12 +45,6 @@ function runThread(generator, onsuccess, onerror)
|
||||||
return thread;
|
return thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
function continueThread()
|
|
||||||
{
|
|
||||||
// pass parameters as yield result
|
|
||||||
callGen(this, 'next', Array.prototype.slice.call(arguments, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
function getStack(fn)
|
function getStack(fn)
|
||||||
{
|
{
|
||||||
return fn._stack.replace(/Error[\s\S]*at.*(exports\.(cb|ef|errorfirst)|Function\.(errorFirst|threadCallback)).*/, '');
|
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)
|
else if (typeof v.value == 'object' && v.value.then)
|
||||||
{
|
{
|
||||||
// check if v.value is a Promise
|
// check if v.value is a Promise
|
||||||
var cb = threadCallback.call(current);
|
var cb = threadCallback.call(thread);
|
||||||
v.value.then(cb, function(error)
|
v.value.then(cb, function(error)
|
||||||
{
|
{
|
||||||
callGen(thread, 'throw', error);
|
callGen(thread, 'throw', error);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "gen-thread",
|
"name": "gen-thread",
|
||||||
"version": "1.0.0",
|
"version": "1.0.1",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "Vitaliy Filippov",
|
"name": "Vitaliy Filippov",
|
||||||
"email": "vitalif@yourcmc.ru"
|
"email": "vitalif@yourcmc.ru"
|
||||||
|
|
Loading…
Reference in New Issue