Skip to content

kotlinx.coroutines.channels.LazyBroadcastCoroutine cannot be cast to kotlinx.coroutines.channels.ConflatedBroadcastChannel #815

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nbransby opened this issue Nov 9, 2018 · 5 comments

Comments

@nbransby
Copy link

nbransby commented Nov 9, 2018

I would expect this to be a ConflatedBroadcastChannel, in fact I would like an api where I would not have to cast

/** use this to show that at least one other team mate is currently online (or not) */
val indicateOnlne = users.openSubscription()
            .map { it.count { user -> user.online } }
            .map { it > 1 }
            .broadcast(capacity = Channel.CONFLATED) as ConflatedBroadcastChannel

Also in the meantime is there a workaround for creating a ConflatedBroadcastChannel from an existing ReceiveChannel?

@qwwdfsad
Copy link
Member

broadcast(capacity = Channel.CONFLATED) behaves like a ConflatedBroadcastChannel but is not an instance of ConflatedBroadcastChannel (and documentation does not guarantee so).
Under the hood, it creates a more efficient version of "launched coroutine + channel" and it implements only BroadcastChannel. It is not easy to make it ConflatedBroadcastChannel as well, because it is a class, not an interface.

Also in the meantime is there a workaround for creating a ConflatedBroadcastChannel from an existing ReceiveChannel?

By manually implementing it with launch coroutine. While it is possible to provide a new API, could you please elaborate why do you need exactly ConflatedBroadcastChannel?

@nbransby
Copy link
Author

nbransby commented Nov 12, 2018

My use case is to remove the member variable and change this line...

https://github.com/TeamHubApp/intellij-plugin/blob/master/src/main/kotlin/app/teamhub/UserNode.kt#L75

...to....

presentation.presentableText = model.title.value

and documentation does not guarantee so

I suggest you make that clearer in the documentation

* * when `capacity` is [CONFLATED] -- uses [ConflatedBroadcastChannel] that conflates back-to-back sends;

@qwwdfsad
Copy link
Member

As a temporary workaround you can use model.title.poll ?: error("...")

qwwdfsad added a commit that referenced this issue Nov 16, 2018
@nbransby
Copy link
Author

nbransby commented Dec 7, 2018

Thanks for the workaround I added:

val <E> BroadcastChannel<E>.value get() = openSubscription().poll()!!

in anticipation of a being able to use a real ConflatedBroadcastChannel sometime in the future!

@qwwdfsad qwwdfsad removed the docs KDoc and API reference label May 28, 2019
@qwwdfsad
Copy link
Member

Broadcast channels are obsolete and will be superseded by the corresponding Flow primitives, so closing as "won't fix"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants