Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'eventmachine'
- class Actor
- def initialize(&cb)
- @channel = EM::Channel.new
- @sid = @channel.subscribe &cb
- end
- def << message
- @channel.push message
- end
- def die
- @channel.unsubscribe(@sid)
- end
- end
- class Player < Actor
- def initialize(output)
- cb = lambda do |message|
- if message == "play"
- puts "playing #{output}"
- end
- end
- super &cb
- end
- end
- EM::run {
- rock_n_roll = Player.new("AC/DC")
- classical = Player.new("Mozart")
- rock_n_roll << "play"
- classical << "play"
- EM::stop_event_loop
- }
Add Comment
Please, Sign In to add comment