I am implementing an event driven system where a c...
# server
s
I am implementing an event driven system where a consumer may need to process 1 to many event ReceiverChannels. First time I have had a use case for something like this, so I was looking for feedback if this was the right way to do it or if Kotlin already has a construct for "funneling" channels into a single receiver:
a
each consumer processes from multiple channels?
s
Yes, exactly. These are different events that can trigger actions needed to be taken by the consumer. However, the events need to be processed in serial (rather they just can't alter consumer state at the same time). I just thought alternatively I could put a mutex on the consumer code instead. I just thought Kotlin is usually able to be expressed more elegantly than that though.
a
If i understand correctly, you can have a channel where the event type is encoded in the message. Have 1 channel that is used for sending and receiving. The receiver then uses the event type to figure out the logic it needs to do. The events in each consumer will be done serially. And one event will only be consumed by one consumer. Then you can scale consumers and producers however you see fit As long as the consumers and producers don't touch shared data except for the channel you shpuld be good
s
Ok, thanks for your help!