onReceive not called when message is broadcasted as soon as channel is subscribed.
mansi-27 opened this issue · comments
I have used action cable at multiple places in my project, and everywhere it works perfectly fine except for the one scenario where message is broadcasted as soon as channel is subscribed, is it something related to synchronisation ?
I'm seeing this happen as well. I've added some logging to ActionCableClient.swift
it seems like there is a race condition wrt when onMessage()
is firing.
- I send the
subscribe
message onText()
fires with theconfirm_subscription
messageonText()
fires with the payload I wantonMessage()
fires with the payload I want (message.messageType == .message
)onMessage()
fires with the.confrimSubscription
message
Obviously, 4) and 5) should be flipped, because otherwise the channel is still unconfirmed when the message comes in, which means my onReceive
block is not firing...
@danielrhodes given that in most cases, the order in which messages are consumed matters, would it make more sense to use a serial queue in onText()
?
@giaset @danielrhodes Order definitely matters if messages to unconfirmedChannels
are ignored