Per claudio-scandura example I am creating stream for pushing events to web browser. As a result of adding heartbeat I get a message triggered every second. In my case I am pushing data from server side with specific eventType myEvent which is handled by adding addEventListener(‘myEvent’…). Do I need to add listeners for onmessage to ‘read’ the heartbeat to avoid memory issues or can I just ignore?
lazy val (sourceQueue, eventsSource) = Source.queue[String](Int.MaxValue, OverflowStrategy.backpressure)
.delay(1.seconds, DelayOverflowStrategy.backpressure)
.map(message => ServerSentEvent(message, Some("myEvent")))
.keepAlive(1.second, () => ServerSentEvent.heartbeat)
.toMat(BroadcastHub.sink[ServerSentEvent])(Keep.both)
.run()