nv-facutil-generator-return
- change/recover the puzzled behavior of generator-return
- npm install nv-facutil-generator-return
> function * gen () {
... yield 1;
... yield 2;
... yield 3;
... }
undefined
>
> var g = gen()
undefined
>
>
> for(let each of g) {
... break; //==================>
... }
>
> g.next()
{ value: undefined, done: true } //======>this behavior NOT make sense
>
> disable() //===========> disable this behavior
>
> function * gen () {
... yield 1;
... yield 2;
... yield 3;
... }
undefined
>
> var g = gen()
undefined
>
>
> for(let each of g) {
... break;
... }
undefined
>
> g.next() //===============>
{ value: 2, done: false }
> g.next() //===============>
{ value: 3, done: false }
> g.next() //===============>
{ value: undefined, done: true }
>
recover to default behavior
enable() //recover the default behavior
> function * gen () {
... yield 1;
... yield 2;
... yield 3;
... }
undefined
>
> var g = gen()
undefined
>
>
> for(let each of g) {
... break;
... }
undefined
>
> g.next()
{ value: undefined, done: true }
>
function *gen() {
let c = 0
while(true) {
yield(c);
c = c +1
}
}
var original = gen()
var sg = sync_yield_with_limit(original,4,17)
> (sg.next().value)
[ 0, 1, 2, 3 ]
> (sg.next().value)
[ 4, 5, 6, 7 ]
> (sg.next().value)
[ 8, 9, 10, 11 ]
> (sg.next().value)
[ 12, 13, 14, 15 ]
> (sg.next().value)
[ 16, 17 ]
> (sg.next().value)
undefined
>
//continue
var sg = sync_yield_with_limit(original,3,Infinity)
/*
> (sg.next().value)
[ 18, 19, 20 ]
> (sg.next().value)
[ 21, 22, 23 ]
> (sg.next().value)
[ 24, 25, 26 ]
> (sg.next().value)
[ 27, 28, 29 ]
> (sg.next().value)
[ 30, 31, 32 ]
>
*/
- grtrn.GCTOR_PROT
- grtrn.ORIG_RTRN
- grtrn.enable()
- grtrn.disable()
- sync_yield_with_limit(g,limit=2,max_count=Infinity)
- async_yield_with_limit(ag,limit=2,max_count=Infinity)