What is equivalent to RxJava PublishSubject in cor...
# coroutines
r
What is equivalent to RxJava PublishSubject in coroutine channels?
o
I’m using
BroadcastChannel<Any>(1)
Where
Any
is your object
1
is for any positive number less the max of int
a
Isn't
BroadcastChannel<T>
deprecated in favor of
flow
?
o
I think we don’t have any
Flow
that acts as a
PublichSubject
until now
But we’ll have something similar soon
f
o
Thanks, @flosch!
r
Thanks @orafaaraujo
👍 1
w
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
Nice approach 😉
t
A possible option until official support is available: https://github.com/akarnokd/kotlin-flow-extensions#publishsubject
👏🏾 1
130 Views