Skip to content

Instantly share code, notes, and snippets.

@Fishrock123
Created August 28, 2019 23:06
Show Gist options
  • Select an option

  • Save Fishrock123/5d44f326a1db607781efb38af6409f29 to your computer and use it in GitHub Desktop.

Select an option

Save Fishrock123/5d44f326a1db607781efb38af6409f29 to your computer and use it in GitHub Desktop.

Revisions

  1. Fishrock123 created this gist Aug 28, 2019.
    25 changes: 25 additions & 0 deletions async-iterator-break-yield.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    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)