Hello everyone! I'm trying to use a `RendezvousCha...
# coroutines
h
Hello everyone! I'm trying to use a
RendezvousChannel
in the place of
PublishSubject
from RxJava in a project, but I need a way to access the current element in the channel without removing it. Something like a 'peek' operation on a
LinkedBlockingQueue
. Now a
RendezvousChannel
has a method called
poll()
which does give me the current element (or null) but it also removes it from the channel. How can I perform a peek operation on a channel then?
l
Hello! You're using the wrong type of channel. You need to use
ConflatedBroadcastChannel
which is the correct analogue to RxJava's
PublishSubject
.
g
ConflatedBroadcastChannel is more like BehaviorSubject
l
Possible, I'm really not familiar with RxJava.
ConflatedBroadcastChannel
has a
value
property to get last value without removing it though, so it suits the use case here.
g
Also, I would say, that you cannot get current value of PublishSubject, PublishSubject analogue in coroutines is BroadcastChannel, but you also cannot get last emitted value without consuming it, this possible with ConflatedBroadcastChannel/BehaviorSubject, but it also means that every new subscriber also will get this value on subscribe (so, not like with PublishSubject)
h
You're right, I mixed
PublishSubject
with
BehaviourSubject
. A
BehaviourSubject
is what I meant to say.
ConflatedBroadcastChannel
looks to be the tool I need. Thanks for your help!