Skip to content

Instantly share code, notes, and snippets.

@Fishrock123
Created August 28, 2019 23:06
Show Gist options
  • Save Fishrock123/5d44f326a1db607781efb38af6409f29 to your computer and use it in GitHub Desktop.
Save Fishrock123/5d44f326a1db607781efb38af6409f29 to your computer and use it in GitHub Desktop.
async-iterator-break-yield.js
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