December 2017
Intermediate to advanced
260 pages
7h 34m
English
The ReactiveBroadcaster class is an event broadcaster that handles the responsibility of subscribing the observers and sending the updates to interested observers asynchronously and will also do the cleanup after the completion of the events:
/** * Handles the event broadcasting to the observers in an * asynchronous way. */ class ReactiveBroadcaster { /** * Set of emitters for multiple events */ private var emitters = synchronizedSet(HashSet<SseEmitter>()) /** * Subscribe to the event */ fun subscribe(): SseEmitter { val sseEmitter = SseEmitter() // Stop observing the event on completion sseEmitter.onCompletion( {this.emitters.remove(sseEmitter) }) this.emitters.add(sseEmitter) return sseEmitter } /** * Trigger the event ...
Read now
Unlock full access