hardStudy question · answer published in JavaScript interview questions, so no pointsjavascriptgeneratorsasync-await
Breaking out of for await
An async generator opens a database cursor and closes it in a finally block. What happens when the loop breaks early?
async function* rows() {
const cur = await db.openCursor()
try {
for await (const r of cur) yield r
} finally {
await cur.close()
}
}
for await (const r of rows()) {
if (r.id === 10) break
}Discussion 0
Join free to post in the discussion.
Related questions
- Block scope of letFrontend Developer
- Loose vs strict equalityFrontend Developer
- Sync code runs before promise callbacksFrontend Developer
- typeof null and arraysFrontend Developer
- Changing a property of a const objectFrontend Developer
- Numbers saved in localStorageFrontend Developer
- What fetch does on a 404Frontend Developer
- Optional chaining on missing dataFrontend Developer