Closed sigil66 closed 8 years ago
Hi, can you elaborate on what you mean by "does not block"?
Sure, if I utilize async methods on objects such as an httpclient, vertx_stop executes but none of the async methods do. No error is printed. So while this may be correct given the lifecycle (has the event loop been stopped?) it wasn't obvious to me that there was an issue until digging into it.
Perhaps you could illustrate what you mean with an example? I'm still not clear what you mean here.
@client = $vertx.create_http_client({
'defaultHost' => 'localhost',
'defaultPort' => 8500
})
def vertx_stop
puts "vertx_stop called" #prints to console
@client.request(:GET, "/some/path") { |response|
if response.status_code() == 200
puts "Success!" # Never executes, no output
else
puts "Failed!" # Never executes, no output
end
}.end()
end
That happens due to the synchronicity of the code. Look at the flow:
As you can see, your callback handler will not be called since the event loop is already dead.
In order to have it called you need to wait, probably using the method variant with a future.
Great, thank you for the help!
When running a ruby script as a verticle it would appear that vertx_stop does not block. I am not sure if this is the intent.
I have gotten around the issue utilize the vertx_stop_async method and completing the future after the async block completes.
Clarification here would be helpful.