Skip to content

Commit 4cbc3ac

Browse files
committed
Remove async connections
This library is not thread-safe
1 parent f269fcb commit 4cbc3ac

3 files changed

Lines changed: 5 additions & 65 deletions

File tree

README.rdoc

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -46,35 +46,6 @@ The application will pause at socket.connect and handle events from Pusher as th
4646

4747
socket.connect
4848

49-
== Asynchronous Usage
50-
The socket will remain open in the background as long as your main application thread is running,
51-
and you can continue to subscribe/unsubscribe to channels and bind new events.
52-
53-
require 'pusher-client'
54-
socket = PusherClient::Socket.new(YOUR_APPLICATION_KEY)
55-
socket.connect(true) # Connect asynchronously
56-
57-
# Subscribe to two channels
58-
socket.subscribe('channel1')
59-
socket.subscribe('channel2')
60-
61-
# Bind to a global event (can occur on either channel1 or channel2)
62-
socket.bind('globalevent') do |data|
63-
puts data
64-
end
65-
66-
# Bind to a channel event (can only occur on channel1)
67-
socket['channel1'].bind('channelevent') do |data|
68-
puts data
69-
end
70-
71-
loop do
72-
sleep(1) # Keep your main thread running
73-
end
74-
75-
For further documentation, read the source & test suite. Some features of the JavaScript client
76-
are not yet implemented.
77-
7849
== Native extension
7950
Pusher depends on the websocket[https://github.com/imanel/websocket-ruby] gem
8051
which is a pure Ruby implementation of websockets.

examples/hello_pusher_async.rb

Lines changed: 0 additions & 22 deletions
This file was deleted.

lib/pusher-client/socket.rb

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,29 +62,19 @@ def initialize(app_key, options={})
6262
end
6363

6464
def connect(async = false)
65+
raise "Async is not supported anymore" if async
6566
return if @connection
6667
logger.debug("Pusher : connecting : #{@url}")
6768

68-
if async
69-
@connection_thread = Thread.new do
70-
begin
71-
connect_internal
72-
rescue => ex
73-
send_local_event "pusher:error", ex
74-
end
75-
@connection_thread = nil
76-
end
77-
else
78-
connect_internal
79-
end
69+
connect_internal
8070
self
8171
end
8272

8373
def disconnect(ex = nil)
8474
return unless @connection
8575
logger.debug("Pusher : disconnecting")
8676

87-
@connection.close
77+
@connection.close rescue nil
8878

8979
send_local_event("pusher:connection_disconnected", ex)
9080
end
@@ -215,8 +205,9 @@ def connect_internal
215205
send_local_event(params['event'], params['data'], params['channel'])
216206
end
217207
end
218-
rescue IOError, Errno::EBADF => ex
208+
rescue IOError, Errno::EBADF, SocketError => ex
219209
disconnect(ex)
210+
return ex
220211
end
221212

222213
def send_local_event(event_name, event_data, channel_name=nil)

0 commit comments

Comments
 (0)