https://kotlinlang.org logo
#coroutines
Title
# coroutines
s

spierce7

10/12/2018, 3:47 PM
Something I haven't quite figured out that has been bothering me about the
RendezvousChannel
. The
RendezvousChannel
seems like a
PublishSubject
from RX, but the documentation says something that worries me:
An element is transferred from sender to receiver only when send and receive invocations meet in time
So I understand that before I start listening to the
Channel
, all events emitted to it won't be received. Is it possible though that if I'm already listening to events on the
Channel
that I'll miss any?
v

Vsevolod Tolstopyatov [JB]

10/12/2018, 4:02 PM
PublishSubject
is rather
ConflatedBroadcastChannel
than
RendezvousChannel
. In
RendezvousChannel
element can be received only by one consumer.
RendezvousChannel
documentation tries to say that sender is suspended until it meets the receiver. You can treat
RendezvousChannel
as suspending version of
BlockingArrayQueue
with zero capacity (
java.util.TransferQueue
actually).
s

spierce7

10/12/2018, 4:20 PM
Isn't
ConflatedBroadcastChannel
more like a
BehaviorSubject
, as all subscribers immediately receive the current value upon subscription?
Is there a BroadcastChannel that would provide the same behavior as
PublishSubject
, which is that all receivers are guaranteed to receive every item emitted after subscription, and all items emitted before subscription are lost to that receiver?
d

David W

10/12/2018, 5:26 PM
I have been looking for this too
This is what I've come up with so far, but I'm not 100% sure it's correct
Copy code
private val sender = BroadcastChannel<State>(Channel.CONFLATED)
        val broadcaster = sender.openSubscription().asPublisher()
s

spierce7

10/12/2018, 5:35 PM
I don't think that answers my question. I'm interested to see how @Vsevolod Tolstopyatov [JB] responds.
v

Vsevolod Tolstopyatov [JB]

10/13/2018, 12:12 PM
Yes,
ConflatedBroadcastChannel
is similar to
BehaviorSubject
(still can’t get used to
*Subject
terminology).
all receivers are guaranteed to receive every item emitted after subscription, and all items emitted before subscription are lost to that receiver?
This is plain
BroadcastChannel
.
5 Views