Skip to content

Instantly share code, notes, and snippets.

@jimmys
Created October 26, 2010 18:15
Show Gist options
  • Save jimmys/647464 to your computer and use it in GitHub Desktop.
Save jimmys/647464 to your computer and use it in GitHub Desktop.
Example of em-mysqlplus
require 'fiber'
require 'em-synchrony'
require 'em-mysqlplus'
require 'benchmark'
EventMachine.synchrony do
db = EventMachine::Synchrony::ConnectionPool.new(size: 5) do
EventMachine::MySQL.new(host: 'localhost')
end
multi = EventMachine::Synchrony::Multi.new
multi.add :a, db.aquery("select sleep(1)")
multi.add :b, db.aquery("select sleep(1)")
res = multi.perform
p res
EventMachine.stop
end
@jimmys
Copy link
Author

jimmys commented Oct 26, 2010

@jimmys
Copy link
Author

jimmys commented Oct 26, 2010

When I run this, I get this error:

/home/jimmys/lib/ruby/gems/1.9.1/gems/em-synchrony-0.1.5/lib/em-synchrony/connection_pool.rb:73:in `block in method_missing': undefined method `callback' for nil:NilClass (NoMethodError)
    from /home/jimmys/lib/ruby/gems/1.9.1/gems/em-synchrony-0.1.5/lib/em-synchrony/connection_pool.rb:23:in `execute'
    from /home/jimmys/lib/ruby/gems/1.9.1/gems/em-synchrony-0.1.5/lib/em-synchrony/connection_pool.rb:68:in `method_missing'
    from db2.rb:14:in `block in <main>'
    from /home/jimmys/lib/ruby/gems/1.9.1/gems/em-synchrony-0.1.5/lib/em-synchrony.rb:22:in `call'
    from /home/jimmys/lib/ruby/gems/1.9.1/gems/em-synchrony-0.1.5/lib/em-synchrony.rb:22:in `block (2 levels) in synchrony'

@kyledrake
Copy link

I'm getting this too, just ran into it. Did you ever find a solution for this?

@jimmys
Copy link
Author

jimmys commented Apr 13, 2011

Yes my example was missing this:

require "em-synchrony/em-mysqlplus"

@kyledrake
Copy link

Yep, that did it. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment