Nikola Milovic
09/28/2021, 11:43 AM//inside jsMain actual ChatClient
private val observable : Observable<MessageModel> =
actual fun subscribeToNewMessages(observer or something to subscribe to the stream of messages){
observable.subscribe With The Observer
}
actual fun somehow Clear the Subscription when Neccessary()
socket.on("received_message") { mess ->
observable.somehow Send to observers (mess)
}
Hopefully this makes senseArkadii Ivanov
09/28/2021, 1:00 PMObservable
from your ChatClient.
val observable: Observable<MessageModel> =
observable { emitter ->
socket.on("received_message") { mess ->
emitter.onNext(mess)
}
emitter.setCancellable {
// Called when the observable is unsubscribed (disposed)
// Cancel the socket subscription using its API
// Usually the "on" method should return a cancellation handle
}
}.share() // Add this operator to share the subscription between multiple subscribers, if needed