Class: NeverBlock::DB::FiberedMysqlConnection

Inherits:
Mysql
  • Object
show all
Defined in:
lib/neverblock/io/db/fibered_mysql_connection.rb

Overview

A modified mysql connection driver. It builds on the original pg driver. This driver is able to register the socket at a certain backend (EM) and then whenever the query is executed within the scope of a friendly fiber. It will be done in async mode and the fiber will yield

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ FiberedMysqlConnection

Initializes the connection and remembers the connection params



13
14
15
16
# File 'lib/neverblock/io/db/fibered_mysql_connection.rb', line 13

def initialize(*args)
  @connection_params = args
  super(*@connection_params)
end

Instance Method Details

#query(sql) ⇒ Object Also known as: exec

Assuming the use of NeverBlock fiber extensions and that the exec is run in the context of a fiber. One that have the value :neverblock set to true. All neverblock IO classes check this value, setting it to false will force the execution in a blocking way.



31
32
33
34
35
36
37
38
39
# File 'lib/neverblock/io/db/fibered_mysql_connection.rb', line 31

def query(sql)
  if NB.neverblocking? && NB.reactor.running?
    send_query sql
    NB.wait(:read, IO.new(socket))
    get_result
  else
    super(sql)
  end
end

#real_connect(*args) ⇒ Object Also known as: connect

Does a normal real_connect if arguments are passed. If no arguments are passed it uses the ones it remembers



20
21
22
23
# File 'lib/neverblock/io/db/fibered_mysql_connection.rb', line 20

def real_connect(*args)
  @connection_params = args unless args.empty?
  super(*@connection_params)
end