Module: NeverBlock::DB::FiberedDBConnection
- Included in:
- FiberedMysqlConnection, FiberedPostgresConnection
- Defined in:
- lib/never_block/db/fibered_db_connection.rb
Instance Method Summary collapse
-
#register_with_event_loop(loop) ⇒ Object
Attaches the connection socket to an event loop.
-
#resume_command ⇒ Object
The callback, this is called whenever there is data available at the socket.
-
#unregister_from_event_loop ⇒ Object
Unattaches the connection socket from the event loop.
Instance Method Details
#register_with_event_loop(loop) ⇒ Object
Attaches the connection socket to an event loop. Currently only supports EM, but Rev support will be completed soon.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/never_block/db/fibered_db_connection.rb', line 7 def register_with_event_loop(loop) @fd = socket @io = IO.new(socket) if loop == :em if EM.reactor_running? @em_connection = EM::attach(@io,EMConnectionHandler,self) else raise "REACTOR NOT RUNNING YA ZALAMA" end elsif loop.class.name == "REV::Loop" loop.attach(RevConnectionHandler.new(@fd)) else raise "could not register with the event loop" end @loop = loop end |
#resume_command ⇒ Object
The callback, this is called whenever there is data available at the socket
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/never_block/db/fibered_db_connection.rb', line 35 def resume_command #protection against being called several times if @fiber f = @fiber @fiber = nil f.resume else unregister_from_event_loop end end |
#unregister_from_event_loop ⇒ Object
Unattaches the connection socket from the event loop
25 26 27 28 29 30 31 |
# File 'lib/never_block/db/fibered_db_connection.rb', line 25 def unregister_from_event_loop if @loop == :em @em_connection.detach else raise NotImplementedError.new("unregister_from_event_loop not implemented for #{@loop}") end end |