Re: [whatwg/streams] `.throw()`ing an async iterator (Issue #1284)

In my iteration utils I have an abort routine that `throw()`s first then `return()`s if it doesn't take. This way I can deliver the error if the iterator wants it, but still ensure it closes no matter what happens.

```js
function abort (iterator, error) {
  try {
    const result = iterator.throw(error)
    if (result.done) return
  } catch {
    return
  }
  iterator.return(error)
}
```

But this would change the semantics of iterator use right at the core of the language. That would be a big change.

I was surprised to see loops don't deliver the error, but then I realized just what you said. It may actually not close the iterator, so you really need the `return()` in there somewhere.

There's that additional complication that `throw()` could actually throw a completely new error. I just drop that one, which is kind of awkward.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/issues/1284#issuecomment-1599455317
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/streams/issues/1284/1599455317@github.com>

Received on Tuesday, 20 June 2023 20:31:55 UTC