Skip to content

Instantly share code, notes, and snippets.

@botanicus
Created June 13, 2011 15:38
Show Gist options
  • Select an option

  • Save botanicus/1023001 to your computer and use it in GitHub Desktop.

Select an option

Save botanicus/1023001 to your computer and use it in GitHub Desktop.
em_keyboard_from_instance.rb
#!/usr/bin/env ruby
# encoding: utf-8
# The purpose of this is:
# connection = AMQP.connect
# handler = MyKbdHandlerClass.new(connection) # SO I CAN ACCESS connection from within the handler class.
# EM.open_keyboard(handler)
require "eventmachine"
class MyKbd
include EM::Protocols::LineText2
def receive_line(data)
p [:received, data]
end
end
def EM.open_keyboard_form_instance(instance)
input = read_keyboard
@conns[input] = instance
block_given? and yield instance
instance
end
EM.run do
kbd = MyKbd.new
EM.open_keyboard_form_instance(kbd)
end
@botanicus
Copy link
Copy Markdown
Author

Reply from Aman: EM.open_keyboard Module, connection should work, it will pass connection to the initializer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment