Skip to content

Commit 48475b0

Browse files
committed
Fix cothreads handling of star generators
1 parent 58778c1 commit 48475b0

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

sdk/cothreads.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,17 @@ const CoThreadBase = {
5656
let f = this._func;
5757
let ctx = this._thisCtx;
5858
let callf = this._callf;
59+
const isStar = !('send' in g);
5960
try {
6061
for (let i = 0; i < y; ++i) {
61-
if (!callf(ctx, g.next(), this._idx++, f)) {
62+
let next = g.next();
63+
if (isStar) {
64+
if (next.done) {
65+
throw "complete";
66+
}
67+
next = next.value;
68+
}
69+
if (!callf(ctx, next, this._idx++, f)) {
6270
throw 'complete';
6371
}
6472
}
@@ -212,7 +220,7 @@ exports.CoThreadListWalker = function CoThreadListWalker(func, arrayOrGenerator,
212220
for (let i of arrayOrGenerator) {
213221
yield i;
214222
}
215-
});
223+
})();
216224
}
217225
else {
218226
this._generator = arrayOrGenerator;

0 commit comments

Comments
 (0)