diff --git a/README.rdoc b/README.rdoc index 8972b37..9407536 100644 --- a/README.rdoc +++ b/README.rdoc @@ -46,35 +46,6 @@ The application will pause at socket.connect and handle events from Pusher as th socket.connect -== Asynchronous Usage -The socket will remain open in the background as long as your main application thread is running, -and you can continue to subscribe/unsubscribe to channels and bind new events. - - require 'pusher-client' - socket = PusherClient::Socket.new(YOUR_APPLICATION_KEY) - socket.connect(true) # Connect asynchronously - - # Subscribe to two channels - socket.subscribe('channel1') - socket.subscribe('channel2') - - # Bind to a global event (can occur on either channel1 or channel2) - socket.bind('globalevent') do |data| - puts data - end - - # Bind to a channel event (can only occur on channel1) - socket['channel1'].bind('channelevent') do |data| - puts data - end - - loop do - sleep(1) # Keep your main thread running - end - -For further documentation, read the source & test suite. Some features of the JavaScript client -are not yet implemented. - == Native extension Pusher depends on the websocket[https://github.com/imanel/websocket-ruby] gem which is a pure Ruby implementation of websockets. diff --git a/examples/hello_pusher_async.rb b/examples/hello_pusher_async.rb deleted file mode 100644 index f022202..0000000 --- a/examples/hello_pusher_async.rb +++ /dev/null @@ -1,22 +0,0 @@ -# Usage: $ PUSHER_KEY=YOURKEY ruby examples/hello_pusher.rb - -$:.unshift(File.expand_path("../../lib", __FILE__)) -require 'pusher-client' -require 'pp' - -APP_KEY = ENV['PUSHER_KEY'] # || "YOUR_APPLICATION_KEY" - -socket = PusherClient::Socket.new(APP_KEY) -socket.connect(true) - -# Subscribe to a channel -socket.subscribe('hellopusher') - -# Bind to a channel event -socket['hellopusher'].bind('hello') do |data| - pp data -end - -loop do - sleep 1 -end diff --git a/lib/pusher-client/socket.rb b/lib/pusher-client/socket.rb index 0c3906f..d1b4abb 100644 --- a/lib/pusher-client/socket.rb +++ b/lib/pusher-client/socket.rb @@ -62,21 +62,11 @@ def initialize(app_key, options={}) end def connect(async = false) + raise "Async is not supported anymore" if async return if @connection logger.debug("Pusher : connecting : #{@url}") - if async - @connection_thread = Thread.new do - begin - connect_internal - rescue => ex - send_local_event "pusher:error", ex - end - @connection_thread = nil - end - else - connect_internal - end + connect_internal self end @@ -84,7 +74,7 @@ def disconnect(ex = nil) return unless @connection logger.debug("Pusher : disconnecting") - @connection.close + @connection.close rescue nil send_local_event("pusher:connection_disconnected", ex) end @@ -215,8 +205,9 @@ def connect_internal send_local_event(params['event'], params['data'], params['channel']) end end - rescue IOError, Errno::EBADF => ex + rescue IOError, Errno::EBADF, SocketError => ex disconnect(ex) + return ex end def send_local_event(event_name, event_data, channel_name=nil)