Replay channel


I have been experimenting with converting some of my existing code implemented using RxJava to Kotlin coroutines. Occasionally I’m using Observable.replay(n) which will replay at most the last n emitted items. I was searching for an alternative for channels but don’t yet have a nice solution.

Wondering if there is a channel implementation that I missed or any suggestions for achieving a similar result ?
Note entirely sure I’m going to need this in the long run, but would be interested regardless.




ConflatedBroadcastChannel should be the one you’re looking for.

There’s an ongoing discussion about it here.


Thanks @bohsen. That’s what I came up with eventually but a mistake I made didn’t yield the result I was looking for. After you reply I checked my code again and found where I have gotten wrong.