Propagating contect down a stream

25 views
Skip to first unread message

Malibu

unread,
May 11, 2023, 10:58:23 AM5/11/23
to Dart Misc
Hi there, further to my last post, I have the following stream:

1     2     3     4     5
+=====+=====+-----+-----+

1. Add a command object to subscribe to a wamp channel to a subject.
2. The wamp client processes the command and gets the channel name and does the subscription, and emits the subscription result.
3. flatMap on the subscription result stream and return the event stream it contains to start triggering on actual messages in the channel.
4. Map the generic message object to a specific object for the operation that the message contains.

This all works great and is elegant, because I can feed multiple commands into 1 and get the operations from all subscriptions in 5.  That's great and I think what reactive programming is for.  However now I have a problem.  When I get a message into 5, I need to know what subscription channel it came from, but that context is lost when I switch from the subscription result stream to the message stream in 3.

How do you deal with passing important context downstream in rxdart?  I have thought of some alternatives but none are terribly elegant:

1. Have the flatmap create a stream that adds the data to a list/map/tuple with every message that the stream emits.  This is just plain messy as it requires me to index into a structure for every operation down stream.
2. Have the flatmap create a stream that adds the data to the object itself.  This is also messy because I have to change the factory method that is used in 4 that reacts to the message to consider handling the data as well.

Is there some sort of way to add context downstream of a flatmap?

I hope I made sense, thanks.
Reply all
Reply to author
Forward
0 new messages