Re: [streams] Change the model for ReadableStream to have async read() (#296)

> -          if (source.state === 'readable') {
> -            Promise.race([source.closed, dest.ready]).then(doPipe, doPipe);
> -          } else if (source.state === 'waiting') {
> -            Promise.race([source.ready, dest.ready]).then(doPipe);
> -          } else if (source.state === 'errored') {
> -            source.closed.catch(abortDest);
> -          } else if (source.state === 'closed') {
> -            closeDest();
> -          }
> -        } else if (ds === 'errored' && (source.state === 'readable' || source.state === 'waiting')) {
> -          dest.closed.catch(cancelSource);
> -        } else if ((ds === 'closing' || ds === 'closed') &&
> -            (source.state === 'readable' || source.state === 'waiting')) {
> -          cancelSource(new TypeError('destination is closing or closed and cannot be piped to anymore'));
> +      lastRead = reader.read();
> +      Promise.all([lastRead, dest.ready]).then(([{ value, done }]) => {

Fixed by adding ` if (dest.state === 'writable')` below (line 93). All tests still pass as expected.

Might be a nicer way to do this algorithm that avoids closedPurposefully by checking dest.state more thoroughly. We will see if that is possible later, I think. When move pipeTo into the main spec seems like a good opportunity.

---
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/pull/296/files#r26484018

Received on Monday, 16 March 2015 13:37:49 UTC