Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider using of "broadcast" operator for async sequnce for multiple iterations over one sequnce #44

Open
maratal opened this issue Sep 14, 2024 · 0 comments

Comments

@maratal
Copy link
Collaborator

maratal commented Sep 14, 2024

          You can't reuse the same `MockMessageSubscription`. It wraps an `AsyncStream`, which is only designed to be iterated over once (I think that the terminology I’ve seen used is that it’s "unicast"). This means that a user who calls `messages.subscribe(bufferingPolicy:)` twice and then iterates over the returned sequences will see that each iteration does not receive all of the messages. (To see this in a more concrete fashion, change your `AblyChatExampleApp` to include two `ContentView` instances instead of one, and you’ll see that when you send a message it only appears in one of the content views.)
          I’m not yet sure what the best way to solve this is — my first thought was to say to just create a new `MockMessageSubscription` each time `messages.subscribe(bufferingPolicy:)` is called, but this wouldn't be right because the timers wouldn't be in sync and the random elements would be different. The ideal thing would be to use some sort of "broadcast" operator (see e.g. [this swift-async-algorithms discussion](https://forums.swift.org/t/swift-async-algorithms-proposal-broadcast-previously-shared/61210)) to allow multiple iterations over a single subscription. Will think about it a bit more, keen to hear your thoughts too.
          Ditto for the other subscriptions (reactions etc).

Originally posted by @lawrence-forooghian in #34 (comment)

@maratal maratal changed the title Consider using using of "broadcast" operator for async sequnce for multiple iterations over one sequnce Consider using of "broadcast" operator for async sequnce for multiple iterations over one sequnce Sep 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant