Question

I'm subscribing to a PubNub channel through EventMachine, however I currently only receive one and only one message posted to the channel.

EventMachine.run {
pubnub.subscribe({
'channel'  => @channel,
'callback' => lambda do |message|
puts(message)
end  
})
}

In other words, I'm looking for a way to make the callbacks "more" asynchronous. I guess I could wrap it in a periodic_timer but I have a bad feeling about this approach. Are there any best practices in this field I should now about?

Edit: The solution to my problems was to, first of all, add 'return true' in the subscribe loop so that it continues to listen. But more importantly, spawning EM in a new thread that listens to whatever channels needed and then dispatching it all to one channel that the client listens to. This solved my problems with handling multiple channels without either the server or client freezing/timing out/overflowing. See http://www.pubnub.com/blog/ruby-push-api.

Was it helpful?

Solution 2

I had forgotten to add:

return true

It now continues to listen. The stack overflows after a few minutes though, but that's another question.

OTHER TIPS

A new, completely rewritten PubNub version 3.3 gem is going to be released within 24 hours.

I'll alert you when it has been released, and if you experience any issues with this new gem, we'll troubleshoot it from there.

geremy

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top