You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
asyncfunction*concat(a,b){yield*a;yield*b;}asyncfunction*gen(str){try{yieldstr+"1";yieldstr+"2";yieldstr+"3";}finally{console.log("closed "+str);}}forawait(constchunkofconcat(gen("a"),gen("b"))){console.log(chunk);if(chunk==="a2")break;}// oops, we never closed `b`!
I think the behavior of the concat function there is not what we want. concat (or whatever equivalent we go with) is logically "taking ownership" of any iterators passed into it, which means it is responsible for closing them.
Practically, I think that means looking at each of the arguments it hasn't gotten to yet, checking to see if they have a next and return, and calling return if so. This has the downside that something with both a next and a Symbol.iterator which is not just return this will behave differently depending on when exactly concat is closed, since the approach I've outlined will check next first whereas we normally check Symbol.iterator first.
Alternatively we could do GetIteratorFlattenable and then IteratorClose, but that has the downside of opening iterators from iterables which we aren't otherwise touching. I guess the consistency argument is maybe worth that cost? Unclear.
The text was updated successfully, but these errors were encountered:
Consider
(slightly simplified from here).
I think the behavior of the
concat
function there is not what we want.concat
(or whatever equivalent we go with) is logically "taking ownership" of any iterators passed into it, which means it is responsible for closing them.Practically, I think that means looking at each of the arguments it hasn't gotten to yet, checking to see if they have a
next
andreturn
, and callingreturn
if so. This has the downside that something with both anext
and aSymbol.iterator
which is not justreturn this
will behave differently depending on when exactlyconcat
is closed, since the approach I've outlined will checknext
first whereas we normally checkSymbol.iterator
first.Alternatively we could do
GetIteratorFlattenable
and thenIteratorClose
, but that has the downside of opening iterators from iterables which we aren't otherwise touching. I guess the consistency argument is maybe worth that cost? Unclear.The text was updated successfully, but these errors were encountered: