Re: [streams] First draft at tee algorithms, for critique (#302)

@wanderview great question. Fortunately I think we took care of it with the reader design :).

To read from a stream, you need to acquire a reader: so, `var reader = resp.body.getReader(); var readPromise = reader.read()`.

If anyone else wants to read from the stream---say, the clone procedure---they will need to also get a reader. But, they cannot get a reader at the same time as you. So, you need to release your reader first.

AND! You're not allowed to release your reader, until all of the read-promises you've asked the reader to create, have settled.

So, the example is more like:

```js
var reader = resp.body.getReader();
var readPromise = reader.read();

// this will throw, since it needs to get a reader, but the stream is already locked
try {
  var resp2 = resp.clone();
} catch (e) { }

// this will also throw, since we haven't waited for readPromise to settle
try {
  reader.releaseLock();
} catch (e) { }

// this will work:
readPromise.then(_ => {
  reader.releaseLock();
  var resp2 = resp.clone();
});
```

Make sense?

---
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/pull/302#issuecomment-84022419

Received on Friday, 20 March 2015 14:01:48 UTC