Re: [streams] Transform streams and acknowledgement of writes (#329)

> I agree that people who want to use the most basic one shouldn't be bothered to understand the other extended ones. I need to explore more to realize it.

Here's the algorithm.

| action happened | current state | things to do |
|---|---|---|
| writer.write(x) | no pending read | queue |
| bufferBorrowingWriter.write(x) | no pending read | leave it pending |
| bufferProvidingWriter.beginWrite() | no pending read | leave it pending |
| reader.read() | no pending write | leave it pending |
| byobReader.read(x) | no pending write | leave it pending |
| bufferLendingReader.read() | no pending write | leave it pending |
| writer.write(x) | pending reader.read() | fulfill read() with x |
| reader.read() | x in queue | Same |
| writer.write(x) | pending byobReader.read(y) | copy bytes from y to x; queue.push(xRemaining) |
| byobReader.read(y) | x in queue | Same |
| writer.write(x) | pending bufferLendingReader.read() | fulfill read() with x (no-op (GC) on ack) |
| bufferLendingReader.read() | x in queue | Same |
| bufferBorrowingWriter.write(x) | pending reader.read() | clone x and fulfill read() with xClone; return x |
| reader.read() | pending bufferBorrowingWriter.write(x) | Same |
| bufferBorrowingWriter.write(x) | pending byobReader.read(y) | copy bytes from y to x; return x or borrowedQueue.push(xRemaining) |
| byobReader.read(y) | pending bufferBorrowingWriter.write(x) | Same |
| bufferBorrowingWriter.write(x) | pending bufferLendingReader.read() | fulfill read() with x (return x on ack) |
| bufferLendingReader.read() | pending bufferBorrowingWriter.write(x) | Same |
| bufferProvidingWriter.beginWrite() | pending reader.read() | allocate buffer; give buffer to producer; fulfill read() with buffer on ack |
| reader.read() | pending bufferProvidingWriter.beginWrite() | Same |
| bufferProvidingWriter.beginWrite() | pending byobReader.read(x) | give x to producer; fulfill on ack |
| byobReader.read(x) | pending bufferProvidingWriter.beginWrite() | Same |
| bufferProvidingWriter.beginWrite() | pending bufferLendingReader.read() | allocate buffer; give buffer to producer; fulfill read() with buffer on ack; no-op (GC) on reader side ack |
| bufferLendingReader.read() | pending bufferProvidingWriter.beginWrite() | Same |


---
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/issues/329#issuecomment-112673762

Received on Wednesday, 17 June 2015 06:40:37 UTC