You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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) 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).
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
You can't reuse the same
MockMessageSubscription
. It wraps anAsyncStream
, 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 callsmessages.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 yourAblyChatExampleApp
to include twoContentView
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 timemessages.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) 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)
┆Issue is synchronized with this Jira Task by Unito
The text was updated successfully, but these errors were encountered: