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

rmyhal

08/03/2020, 1:11 PM
What is equivalent to RxJava PublishSubject in coroutine channels?
o

orafaaraujo

08/03/2020, 1:13 PM
I’m using
BroadcastChannel<Any>(1)
Where
Any
is your object
1
is for any positive number less the max of int
a

andylamax

08/03/2020, 1:15 PM
Isn't
BroadcastChannel<T>
deprecated in favor of
flow
?
o

orafaaraujo

08/03/2020, 1:16 PM
I think we don’t have any
Flow
that acts as a
PublichSubject
until now
But we’ll have something similar soon
f

flosch

08/03/2020, 1:16 PM
o

orafaaraujo

08/03/2020, 1:17 PM
Thanks, @flosch!
r

rmyhal

08/03/2020, 1:30 PM
Thanks @orafaaraujo
👍 1
w

wasyl

08/03/2020, 1:33 PM
This is what we’ve used to migrate from RxJava, to make it easier to see the parallel API
Copy code
typealias PublishChannel<T> = BroadcastChannel<T>

typealias BehaviorChannel<T> = ConflatedBroadcastChannel<T>

fun <T> publishChannel(): PublishChannel<T> = BroadcastChannel(1)

fun <T> behaviorChannel(defaultValue: T? = null): BehaviorChannel<T> =
    defaultValue?.let { ConflatedBroadcastChannel(it) } ?: ConflatedBroadcastChannel()
👌 2
o

orafaaraujo

08/03/2020, 2:03 PM
Nice approach 😉
t

travis

08/04/2020, 4:56 PM
A possible option until official support is available: https://github.com/akarnokd/kotlin-flow-extensions#publishsubject
👏🏾 1
109 Views