Do not wait on promises if caller sets a callback explicitly
parent
368485f50d
commit
48e62b44b5
7
index.js
7
index.js
|
@ -107,9 +107,10 @@ function callGen(thread, method, arg)
|
||||||
}
|
}
|
||||||
else if (v.done && thread._onsuccess)
|
else if (v.done && thread._onsuccess)
|
||||||
thread._onsuccess(v.value);
|
thread._onsuccess(v.value);
|
||||||
else if (typeof v.value == 'object' && v.value.then)
|
else if (typeof v.value == 'object' && v.value.then && !thread._current)
|
||||||
{
|
{
|
||||||
// check if v.value is a Promise
|
// check if v.value is a Promise
|
||||||
|
// (but not if an explicit .then(gen.cb()) callback is already set by caller)
|
||||||
v.value.then(function(value)
|
v.value.then(function(value)
|
||||||
{
|
{
|
||||||
// use process.nextTick so Promise does not intercept our exceptions
|
// use process.nextTick so Promise does not intercept our exceptions
|
||||||
|
@ -141,6 +142,7 @@ function threadCallback()
|
||||||
getStack(fn)+'\n--'
|
getStack(fn)+'\n--'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
thread._current = null;
|
||||||
return callGen(thread, 'next', Array.prototype.slice.call(arguments, 0));
|
return callGen(thread, 'next', Array.prototype.slice.call(arguments, 0));
|
||||||
};
|
};
|
||||||
fn._stack = new Error().stack;
|
fn._stack = new Error().stack;
|
||||||
|
@ -161,12 +163,13 @@ function errorFirst()
|
||||||
getStack(fn)+'\n--'
|
getStack(fn)+'\n--'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
thread._current = null;
|
||||||
if (arguments[0])
|
if (arguments[0])
|
||||||
{
|
{
|
||||||
var e = arguments[0];
|
var e = arguments[0];
|
||||||
var m = /^([\s\S]*?)((\n\s*at.*)*)$/.exec(e.stack);
|
var m = /^([\s\S]*?)((\n\s*at.*)*)$/.exec(e.stack);
|
||||||
if (m)
|
if (m)
|
||||||
e.stack = m[1]+getStack(thread._current)+'\n-- async error thrown at:'+m[2];
|
e.stack = m[1]+getStack(fn)+'\n-- async error thrown at:'+m[2];
|
||||||
return callGen(thread, 'throw', e);
|
return callGen(thread, 'throw', e);
|
||||||
}
|
}
|
||||||
return callGen(thread, 'next', Array.prototype.slice.call(arguments, 1));
|
return callGen(thread, 'next', Array.prototype.slice.call(arguments, 1));
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "gen-thread",
|
"name": "gen-thread",
|
||||||
"version": "1.0.4",
|
"version": "1.0.5",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "Vitaliy Filippov",
|
"name": "Vitaliy Filippov",
|
||||||
"email": "vitalif@yourcmc.ru"
|
"email": "vitalif@yourcmc.ru"
|
||||||
|
|
Loading…
Reference in New Issue