iex
07/12/2020, 5:24 PMBroadcastChannel.send
in a suspended function? With e.g. RxJava pushing events to a subject doesn't require anything special.louiscad
07/12/2020, 5:28 PMoffer
.iex
07/12/2020, 5:30 PMoffer
, but which throws an error if the channel is full (instead of returning false)?runBlocking { observable.send(x) }
louiscad
07/12/2020, 5:34 PMcheck(myBroadcastChannel.offer(element))
launch { myBroadcastChannel.offer(element) }
sendBlocking
if you're sure you need to block the sending thread.iex
07/12/2020, 5:35 PMlaunch
?louiscad
07/12/2020, 5:35 PMiex
07/12/2020, 5:35 PMsendBlocking
is perfect!launch
) would be identical to runBlocking { observable.send(x) }
?louiscad
07/12/2020, 5:37 PMiex
07/12/2020, 5:38 PMlouiscad
07/12/2020, 5:40 PMiex
07/12/2020, 5:40 PMlouiscad
07/12/2020, 5:42 PMiex
07/12/2020, 5:42 PMlouiscad
07/12/2020, 5:43 PMiex
07/12/2020, 5:46 PMlouiscad
07/12/2020, 5:47 PMiex
07/12/2020, 5:49 PMlouiscad
07/12/2020, 6:14 PMiex
07/12/2020, 6:57 PMBroadcastChannel
for where I was using PublishSubject
apparentlyConflatedBroadcastChannel
for BehaviorSubject
from what I just read)louiscad
07/12/2020, 6:58 PMStateFlow
might be a great solution.iex
07/12/2020, 6:58 PMlouiscad
07/12/2020, 6:59 PMMutableStateFlow
iex
07/12/2020, 6:59 PMObservable
)BroadcastChannel
doesn't implement Flow
, so I can't apply the same patternlouiscad
07/12/2020, 7:00 PMiex
07/12/2020, 7:00 PMMutableStateFlow
-> interesting, will give that a look 👍louiscad
07/12/2020, 7:01 PMBroadcastChannel
if you're using MutableStateFlow
and expose StateFlow
or a plain Flow
.iex
07/12/2020, 7:01 PMlouiscad
07/12/2020, 7:01 PMStateFlow
, and upcoming SharedFlow
.iex
07/12/2020, 7:33 PMjulian
07/12/2020, 9:59 PMBroadcastChannel
? @louiscadandylamax
07/13/2020, 12:07 AMlouiscad
07/13/2020, 7:16 AMConflatedBroadcastChannel
in favor of StateFlow
.
BroadcastChannel
, I cannot tell. But they are still safe to use if StateFlow
doesn't suit your use case.andylamax
07/13/2020, 9:29 AMlouiscad
07/13/2020, 9:30 AMandylamax
07/13/2020, 9:31 AMStateFlow
is, I still have partial knowledge on what a SharedFlow
is (Ironic ey? provided that StateFlow
implements SharedFlow
)louiscad
07/13/2020, 9:51 AMZach Klippenstein (he/him) [MOD]
07/13/2020, 2:06 PMStateFlow
is like Rx's BehaviorSubject
, then SharedFlow
is basically like PublishSubject
. However, SharedFlow
actually supports propagating backpressure to the sender, like BroadcastChannel
, so if one of your subscribers is slow, the send call will suspend. SharedFlow
also supports custom replay behavior, so you can make it act like a StateFlow
(but without access to the current value). Both flows are also unlike Subjects in that you can't close or fail them directly, although you can get similar behavior by applying operators to the flows before exposing them.andylamax
07/13/2020, 4:30 PM