-
-
Save chrisdickinson/3e9baccfae6b77fc27a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function *gen() { | |
for(var i = 0, len = 10; i < len; ++i) { | |
try { | |
console.log('try') | |
console.log('got try', yield i) | |
} catch(err) { | |
console.log('catch') | |
console.log('got catch', yield i + 10) | |
} finally { | |
console.log('finally') | |
console.log('got finally', yield i + 20) | |
} | |
} | |
} | |
var iter = gen() | |
, accum = 0 | |
, i = 2 | |
, value | |
do { | |
console.log('---- ' + i +' -----') | |
value = i % 3 === 0 ? | |
iter.throw(new Error('throw')) : iter.next('recv') | |
if(value.value !== undefined) { | |
accum += value.value | |
} | |
++i | |
} while(!value.done) | |
// WHAT IS ACCUM? | |
// how many times did it iterate? | |
console.log(accum, i - 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment