我从 mysql2 gem docs 运行这段代码:
require 'mysql2/em'
EM.run do
client1 = Mysql2::EM::Client.new
defer1 = client1.query "SELECT sleep(3) as first_query"
defer1.callback do |result|
puts "Result: #{result.to_a.inspect}"
end
client2 = Mysql2::EM::Client.new
defer2 = client2.query "SELECT sleep(1) second_query"
defer2.callback do |result|
puts "Result: #{result.to_a.inspect}"
end
end
它运行良好,打印结果
Result: [{"second_query"=>0}]
Result: [{"first_query"=>0}]
但随后脚本只是挂起并且永远不会返回到命令行。知道发生了什么吗?