add fibered em connection without activerecord
This commit is contained in:
parent
550c68cade
commit
c2e2f0c46c
25
lib/mysql2/em_fiber.rb
Normal file
25
lib/mysql2/em_fiber.rb
Normal file
@ -0,0 +1,25 @@
|
||||
# encoding: utf-8
|
||||
|
||||
require 'mysql2/em'
|
||||
require 'fiber' unless defined? Fiber
|
||||
|
||||
module Mysql2
|
||||
module EM
|
||||
module Fiber
|
||||
class Client < ::Mysql2::EM::Client
|
||||
def query(sql, opts={})
|
||||
deferable = super(sql, opts)
|
||||
|
||||
fiber = ::Fiber.current
|
||||
deferable.callback do |result|
|
||||
fiber.resume(result)
|
||||
end
|
||||
deferable.errback do |err|
|
||||
fiber.resume(err)
|
||||
end
|
||||
::Fiber.yield
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -46,6 +46,7 @@ Gem::Specification.new do |s|
|
||||
"lib/mysql2.rb",
|
||||
"lib/mysql2/client.rb",
|
||||
"lib/mysql2/em.rb",
|
||||
"lib/mysql2/em_fiber.rb",
|
||||
"lib/mysql2/error.rb",
|
||||
"lib/mysql2/result.rb",
|
||||
"mysql2.gemspec",
|
||||
|
Loading…
Reference in New Issue
Block a user