Consider clarifying `return` discussion in 21.4.4.1

19 views
Skip to first unread message

Adam Rackis

unread,
Jul 4, 2015, 10:05:16 PM7/4/15
to explor...@googlegroups.com
Toward the bottom of 21.4.4.1 you write:

"You can invoke next() one more time"

Have you considered changing that to something like 

"The generator will now continue processing inside of the finally like normal.  You may yield as many more values from there as you please."

And, if babel is to be believed, it appears as though you can even nest a new try finally block in the first finally, and actually override the previous return() value with a new return()


function* foo(){
  try {
    yield 1;
    yield 2;
  } finally{
    try {
      yield 3;
      yield 4;
    } finally {
      yield 5;
    }
  }
}

var iter = foo();

console.log(iter.next());
console.log(iter.return('X'));
console.log(iter.return('Y'));
console.log(iter.next());
console.log(iter.next());

console.log(iter.next());
console.log(iter.next());
console.log(iter.next());

_____________________________________

{"value":1,"done":false} {"value":3,"done":false} {"value":5,"done":false} {"value":"Y","done":true} {"done":true} {"done":true} {"done":true} {"done":true}


Reply all
Reply to author
Forward
0 new messages