sdeleuze
02/16/2018, 10:07 AMReceiveChannel
to a shared BroadcastChannel
? I try to convert my Reactor SSE example to Coroutines where I want to use a single stream from my Mongo database to a shared broadcasted stream to browsers. Reactor version: https://github.com/sdeleuze/spring-kotlin-deepdive/blob/step3/src/main/kotlin/io/spring/deepdive/web/ArticleController.kt#L51-L52. Coroutines version without the broadcast feature: https://github.com/sdeleuze/spring-kotlin-deepdive/blob/step3-coroutine/src/main/kotlin/io/spring/deepdive/web/ArticleController.kt#L52-L57.Jonathan
02/16/2018, 10:23 AMprivate val notificationBroadcast = BroadcastChannel(1).apply {
launch {
val count = articleEventRepository.count().toInt()
articleEventRepository.findWithTailableCursorBy().drop(count).consumeEach {
send(it)
}
}
}
@GetMapping("/notifications", produces = [(MediaType.TEXT_EVENT_STREAM_VALUE)])
suspend fun notifications(): ReceiveChannel<ArticleEvent> = notificationBroadcast.openSubscription()
Jonathan
02/16/2018, 10:27 AMsdeleuze
02/16/2018, 12:57 PMReceiveChannel
one so I guess something is missing.