Created
August 28, 2019 23:06
-
-
Save Fishrock123/5d44f326a1db607781efb38af6409f29 to your computer and use it in GitHub Desktop.
async-iterator-break-yield.js
This file contains hidden or 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
async function* f() { | |
try { | |
yield Promise.resolve(1) | |
yield Promise.resolve(2) | |
yield Promise.resolve(3) | |
} finally { | |
console.log('inside finally') | |
// yield Promise.resolve(4) | |
console.log('about to reject from finally') | |
yield new Promise((res, rej) => { | |
console.log('inside rejecting promise') | |
rej('oh no') | |
}) | |
yield Promise.resolve(5) | |
} | |
} | |
async function loop () { | |
for await (const val of f()) { | |
console.log(val) | |
if (val === 2) break | |
} | |
} | |
loop().catch(console.error) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment