Detach before executing callbacks.
This allows to make queries in callbacks.
This commit is contained in:
parent
2ae908c512
commit
687487d5a5
@ -13,12 +13,12 @@ module Mysql2
|
|||||||
end
|
end
|
||||||
|
|
||||||
def notify_readable
|
def notify_readable
|
||||||
|
detach
|
||||||
begin
|
begin
|
||||||
@deferable.succeed(@client.async_result)
|
@deferable.succeed(@client.async_result)
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
@deferable.fail(e)
|
@deferable.fail(e)
|
||||||
end
|
end
|
||||||
detach
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -19,8 +19,27 @@ describe Mysql2::EM::Client do
|
|||||||
results << result.first
|
results << result.first
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
results[0].keys.should include("second_query")
|
results[0].keys.should include("second_query")
|
||||||
results[1].keys.should include("first_query")
|
results[1].keys.should include("first_query")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should support queries in callbacks" do
|
||||||
|
results = []
|
||||||
|
EM.run do
|
||||||
|
client = Mysql2::EM::Client.new
|
||||||
|
defer1 = client.query "SELECT sleep(0.025) as first_query"
|
||||||
|
defer1.callback do |result|
|
||||||
|
results << result.first
|
||||||
|
defer2 = client.query "SELECT sleep(0.025) as second_query"
|
||||||
|
defer2.callback do |result|
|
||||||
|
results << result.first
|
||||||
|
EM.stop_event_loop
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
results[0].keys.should include("first_query")
|
||||||
|
results[1].keys.should include("second_query")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user