Suppose I use a library which has a function with unconventional callback argument structure, like:
function myFunction(arg, cb) { cb('a', 'b', 'c', 'd', 'e'); }
when I use resumeRaw like this:
suspend(function*() { console.log(yield myFunction(0, suspend.resumeRaw())); })();
I get: [ 'a', 'b' ]
I modified suspend.js a little bit, to this:
/**
* Resumes execution of the generator once an async operation has completed.
*/
Suspender.prototype.resume = function resume(err, result) {
// if we have been synchronously resumed, then wait for the next turn on
// the event loop (avoids 'Generator already running' errors).
if (this.syncResume) {
return setImmediate(this.resume.bind(this, ...arguments));
// return setImmediate(this.resume.bind(this, err, result));
}
if (this.rawResume) {
this.rawResume = false;
this.nextOrThrow(Array.prototype.slice.call(arguments));
} else {
if (this.done) {
throw new Error('Generators cannot be resumed once completed.');
}
if (err) return this.nextOrThrow(err, true);
this.nextOrThrow(result);
}
};
and got this (my intended result): [ 'a', 'b', 'c', 'd', 'e' ]
Did I do something wrong or it's a bug?
Suppose I use a library which has a function with unconventional callback argument structure, like:
function myFunction(arg, cb) { cb('a', 'b', 'c', 'd', 'e'); }when I use resumeRaw like this:
suspend(function*() { console.log(yield myFunction(0, suspend.resumeRaw())); })();I get:
[ 'a', 'b' ]I modified suspend.js a little bit, to this:
and got this (my intended result):
[ 'a', 'b', 'c', 'd', 'e' ]Did I do something wrong or it's a bug?