Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Hurr, Channels are overkill, just use EM.schedule

  • Loading branch information...
commit 48360fab0546a7d0d2daaace043322ea35d0aa5b 1 parent add3573
@tarcieri authored
Showing with 1 addition and 9 deletions.
  1. +1 −9 app/actions/chat_client.rb
View
10 app/actions/chat_client.rb
@@ -1,19 +1,11 @@
class ChatClient < Cramp::Websocket
attr_reader :name
- on_start :init_channel
on_data :handle_data
on_finish :handle_leave
-
- def init_channel
- # Channels are a thread-safe way to send messages to the event loop
- @channel = EM::Channel.new
- @sub = @channel.subscribe { |msg| render msg }
- end
def handle_data(data)
msg = JSON.parse data
- p msg
case msg['action']
when 'join' then handle_join(msg)
@@ -36,6 +28,6 @@ def handle_message(msg)
end
def send_message(msg)
- @channel.push msg
+ EM.schedule { render msg }
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.