Created
June 13, 2011 15:38
-
-
Save botanicus/1023001 to your computer and use it in GitHub Desktop.
em_keyboard_from_instance.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reply from Aman: EM.open_keyboard Module, connection should work, it will pass connection to the initializer.