Permalink
Browse files

add fibered em connection without activerecord

  • Loading branch information...
1 parent 550c68c commit c2e2f0c46c8c00b0099109cce594be009bc79e4c @dj2 dj2 committed Nov 26, 2010
Showing with 26 additions and 0 deletions.
  1. +25 −0 lib/mysql2/em_fiber.rb
  2. +1 −0 mysql2.gemspec
View
@@ -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
@@ -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",

0 comments on commit c2e2f0c

Please sign in to comment.