Created
July 23, 2013 11:28
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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