whatwg / streams

Streams Standard
https://streams.spec.whatwg.org/
Other
1.34k stars 159 forks source link

Visualize the internal state machines #29

Closed domenic closed 8 years ago

domenic commented 10 years ago

This would be an immensely helpful illustrative diagram to make.

domenic commented 10 years ago

Sketching this out also revealed a few questions. I think this is the correct way to drive development and will be using the below to rewrite the spec's state for clarity and robustness. Please look this over.

Operations

States

Breakdown of States x Operations

Waiting

Readable

Errored

Finished

creationix commented 10 years ago

First off, I really like this style of spec. I write state machines all the time and it's really natural for me. Also it forces you to see all the edge cases formally.

creationix commented 10 years ago

I'm not quite clear on what waitForReadable() actually does. I assume it will return a promise or take a callback to notify the caller when the stream is readable.

domenic commented 10 years ago

I'm not quite clear on what waitForReadable() actually does. I assume it will return a promise or take a callback to notify the caller when the stream is readable.

Right, I left out what it actually does. You're right that's what it's supposed to do. I need to add side effects internally to reset, resolve, or reject the internal promise it returns at the appropriate steps.

Another point: I need to prevent calling pull more than once. This may need another state ("reading?"), or perhaps just a flag.

SimonSapin commented 10 years ago

I’ll just leave this here. https://github.com/tabatkins/railroad-diagrams/

mattpodwysocki commented 10 years ago

I like this way of visualizing through what we call marble diagrams in Rx: http://netflix.github.io/RxJava/javadoc/

benjchristensen commented 10 years ago

Deep link to a page with the marble diagrams: http://netflix.github.io/RxJava/javadoc/rx/Observable.html and one of the wiki pages with them: https://github.com/Netflix/RxJava/wiki/Combining-Observables

I very much want dynamic "Chrome/Webkit Profiler" style visualizations (with relationship between streams added) for these types of systems. That's something we are exploring for tracing live systems.

trevnorris commented 10 years ago

I see a few implementation questions that may or may not need to be addressed here, but I'll bring them up.

domenic commented 10 years ago

@trevnorris thanks for your thoughts; really great to have you join the conversation.

domenic commented 10 years ago

I rewrote things to use a state machine. I think it might be possible to remove the "pulling," "draining," and "opening" flags in favor of more internal states (i.e. ones not exposed through readableState). But this at least fixes a lot of issues and edge cases. Time to move on to writable stream and the toolbox.

domenic commented 10 years ago

Here is a draft of the state machine for readable stream:

http://www.gliffy.com/go/publish/5148129

Diagram

Feedback welcome. Maybe todo:

aredridel commented 10 years ago

++

domenic commented 9 years ago

Two writable stream ideas, one with loopbacks:

http://www.gliffy.com/go/publish/6388889

Writable stream state machine with loopbacks

one without:

http://www.gliffy.com/go/publish/6388970

Writable stream state machine with no loopbacks

Could add loopbacks to readable stream too, unsure.

Would be interested in review before SVG-izing this.

tyoshino commented 9 years ago

The initial state is "Waiting" in the diagram but is "writable" in the spec. Let's discuss in #242