Skip to content

Commit

Permalink
Hurr, Channels are overkill, just use EM.schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
tarcieri committed Sep 17, 2011
1 parent add3573 commit 48360fa
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions 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)
Expand All @@ -36,6 +28,6 @@ def handle_message(msg)
end

def send_message(msg)
@channel.push msg
EM.schedule { render msg }
end
end

0 comments on commit 48360fa

Please sign in to comment.