Adam Bishti
Adam Bishti

Reputation: 545

Ruby, subscribing to PubNub channel does not output any messages

I'm following the Ruby SDK guide.

I can publish successfully but when trying to subscribe, nothing happens as I try to send a message to the channel from the PubNub console.

When running the code, it finishes and exits. No async is happening.

pubnub = Pubnub.new(
  subscribe_key: 'demo', 
  publish_key: 'demo', 
  connect_callback: lambda {|msg| pubnub.publish(channel: 'demo', message: 'Hello from PubNub        Ruby SDK!!', http_sync: true)}
)


pubnub.subscribe(channel: 'demo') do |envelope|
  puts envelope.message
end

Upvotes: 1

Views: 239

Answers (1)

Tomasz Weissbek
Tomasz Weissbek

Reputation: 153

Your program finishes because main thread ends its work and exits before async code gets messages. Just add some sleep time on the end or run this code in pry console.

Upvotes: 2

Related Questions