-
-
Notifications
You must be signed in to change notification settings - Fork 125
Open
Description
Summary
Here's a summary of the discussion between David Golightly and Michael Arnaldi, along with some key takeaways:
Summary:
-
Initial Issue:
- David observed inconsistent behavior when using
Stream.changes
with multiple consumers and sought clarification on whether it was a bug or a documentation issue. - The inconsistency observed was difficult to diagnose and led David to a "correct" solution using
Stream.broadcast
.
- David observed inconsistent behavior when using
-
Michael’s Explanation:
- Michael explained that creating a stream from a queue involves pulling elements from the queue, and when multiple consumers run the stream, elements are dynamically and randomly allocated to the consumers, similar to multiple fibers performing a
take
from the same queue. - He emphasized that broadcasting creates multiple streams with the same elements, unlike plain running where elements get divided among consumers.
- Michael explained that creating a stream from a queue involves pulling elements from the queue, and when multiple consumers run the stream, elements are dynamically and randomly allocated to the consumers, similar to multiple fibers performing a
-
Understanding Conceptual Misunderstanding:
- David initially had a misconception that streams should either consistently succeed or fail to emit events to all consumers.
- Michael clarified that the observed behavior isn't inconsistent; rather, it's determined by how elements are dynamically and randomly allocated among multiple consumers.
-
Discussion on Documentation:
- David suggested that documentation could be improved to make concepts like broadcasting, parallel consumption, and stream pulling clearer to beginners.
- Michael acknowledged this and suggested more explicit notes on the behavior of streams depending on their sources.
-
David’s Request for Examples:
- David pointed out that for beginners, having explicit examples and warnings about certain behaviors (like multiple consumers on the same stream) would be helpful.
- He also mentioned that linking out to relevant sections in the API reference would improve the learning curve for new users.
-
Decoupling Sources and Streams:
- David learned that the behavior of streams can heavily depend on the underlying source, and this can lead to different outcomes based on whether the source is mutable or immutable.
- Michael suggested that understanding these foundational concepts is crucial for correctly using streams in various scenarios.
Key Takeaways:
-
Behavior of Streams:
- The behavior of a stream can depend heavily on its source. For example, streams created from mutable sources like queues will have elements pulled and consumed differently than streams from immutable sources or static arrays.
-
Documentation Needs:
- Documentation should clearly highlight the behaviors of streams with various sources, and examples of what not to do can be beneficial.
- Details about concepts like broadcasting and sharing streams should be emphasized to guide beginners accurately.
-
Parallelism and Consumption:
- Running streams in parallel can lead to elements being divided among consumers, especially if the source is mutable or dynamically allocated.
- It’s important to understand whether a source is replayable or single-use to predict stream behavior accurately.
-
Practical Implementation:
- For state management or real-time applications (like handling WebSocket events), choosing the correct stream creation method and understanding event consumption patterns are crucial.
- Alternatives to queues, like proper broadcasting or other stream combinators, might be more suitable for ensuring all consumers receive all events.
This discussion emphasized the importance of both understanding core concepts in stream consumption and improving documentation to aid in learning and avoiding common pitfalls.
Discord thread
https://discord.com/channels/795981131316985866/1290359110235193364
davidgoli
Metadata
Metadata
Assignees
Labels
No labels