add fibered em connection without activerecord

This commit is contained in:
dj2 2010-11-26 10:52:09 -05:00
parent 550c68cade
commit c2e2f0c46c
2 changed files with 26 additions and 0 deletions

25
lib/mysql2/em_fiber.rb Normal file
View 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

View File

@ -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",