Promises, streams, signals and behaviors, all on one map.
Kris Kowal's gtor sorts reactive primitives by a few questions: one value or many, here now or arriving later, getter or setter. These pages run small, real implementations of each primitive in your browser. The reactor log at the bottom shows every get, set, acknowledgement, push and poll as it happens.
reader.next() → Promise<{value, done}>Rotate an array from the space axis onto the time axis and it becomes a stream. A reader is an async iterator, a writer an async generator.
“If you rotate an array from the space axis to the time axis, it would become a stream. The order is important, and every value is significant.”
| Interface | Role | Number | Axis |
|---|---|---|---|
| Value | Value | Singular | Spatial |
| Getter | Getter | Singular | Spatial |
| Setter | Setter | Singular | Spatial |
| Array | Value | Plural | Spatial |
| Iterator | Getter | Plural | Spatial |
| Generator | Setter | Plural | Spatial |
| Deferred | Value | Singular | Temporal |
| Promise | Getter | Singular | Temporal |
| Resolver | Setter | Singular | Temporal |
| Stream | Value | Plural | Temporal |
| Reader | Getter | Plural | Temporal |
| Writer | Setter | Plural | Temporal |
Lazy beats eager. Pull one value at a time through map, filter and reduce, and watch no array ever get built.
Step through a generator paused at yield. next, throw and return send information back to the producer.
A getter for one value in the future. Subscribe before or after it resolves; race resolvers and only one wins.
A promise that only one consumer may observe, so it can be cancelled. Fork it, cancel the forks, watch the work stop.
A generator plus promises becomes async/await. Step the trampoline that resumes your function.
A queue where you can get before you put. Then use one as a non-blocking semaphore over a connection pool.
Two promise queues make a buffer: values go forward, acks come back. Tune producer and consumer rates to see pressure.
Iteration<Promise<T>> or Promise<Iteration<T>>? Run an async generator and watch await yield wait for the reader.
Discrete values pushed to any number of observers, with no back pressure. Late subscribers miss what came before.
Continuous values with no resolution of their own. The consumer decides when to poll.
Progress and ETA: a discrete signal per value, and a continuous behavior for smooth animation.
Broadcast or unicast? Cancelable? Push, pull or pressure? Answer a few questions to find the right primitive.