Skip to content

Instantly share code, notes, and snippets.

@blazeroot
Created July 23, 2013 11:28
Show Gist options
  • Select an option

  • Save blazeroot/6061671 to your computer and use it in GitHub Desktop.

Select an option

Save blazeroot/6061671 to your computer and use it in GitHub Desktop.
Script showing why PubNub throws server closed connection errors while running small script that tests asynchronous publish.
require 'pubnub'
p = Pubnub.new(
:subscribe_key => 'demo',
:publish_key => 'demo',
:error_callback => lambda{|e| puts "ERROR! #{e.inspect}"; puts "\n";}
)
9001.times do |i|
p.publish(:message => i+1, :channel => 'my_channel', :http_sync => false){|envelope|
p "#{i+1} #{envelope.message}";
@last = i
}
end
while @last < 9000 do end
# Finishes after last callback is made
# No errors
require 'pubnub'
p = Pubnub.new(
:subscribe_key => 'demo',
:publish_key => 'demo',
:error_callback => lambda{|e| puts "ERROR! #{e.inspect}"; puts "\n";}
)
9001.times do |i|
p.publish(:message => i+1, :channel => 'my_channel', :http_sync => false){|envelope|
p "#{i+1} #{envelope.message}";
@last = i
}
end
# Finishes while there are still scheduled requests in EM
# so connection are closed and error_callbacks are fired for each pending request.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment