danielrhodes / Swift-ActionCableClient

ActionCable is a new WebSocket server being released with Rails 5 which makes it easy to add real-time features to your app. This Swift client makes it dead-simple to connect with that server, abstracting away everything except what you need to get going.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

  1. I send the subscribe message
  2. onText() fires with the confirm_subscription message
  3. onText() fires with the payload I want
  4. onMessage() fires with the payload I want (message.messageType == .message)
  5. 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