Re: [whatwg/streams] add @@asyncIterator to ReadableStream (#954)

MattiasBuelens commented on this pull request.



> +</emu-alg>
+
+<h4 id="rs-asynciterator-prototype-return" method
+for="ReadableStreamAsyncIteratorPrototype">return( <var>value</var> )</h4>
+
+<emu-alg>
+  1. If ! IsReadableStreamAsyncIterator(*this*) is *false*, throw a *TypeError* exception.
+  1. Let _reader_ be *this*.[[asyncIteratorReader]].
+  1. If *this*.[[preventCancel]] is *false*, then:
+    1. If _reader_.[[ownerReadableStream]] is *undefined*, return <a>a promise rejected with</a> a *TypeError*
+    exception.
+    1. Let _result_ be ! ReadableStreamReaderGenericCancel(_reader_, _value_).
+    1. Perform ! ReadableStreamReaderGenericRelease(_reader_).
+    1. Return the result of <a>transforming</a> _result_ by a fulfillment handler that returns !
+    ReadableStreamCreateReadResult(_value_, *true*, *true*).
+  1. Perform ! ReadableStreamReaderGenericRelease(_reader_).

It's not impossible for it to be `undefined`, but you really have to go out of your way to break it:
```js
const iterator = readable.getIterator();
iterator.return(); // releases lock
iterator.return(); // boom!
```

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/pull/954#discussion_r216237031

Received on Monday, 10 September 2018 08:32:08 UTC