Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async handlers not working #31

Closed
andrewvc opened this issue Aug 21, 2015 · 2 comments
Closed

Async handlers not working #31

andrewvc opened this issue Aug 21, 2015 · 2 comments

Comments

@andrewvc
Copy link
Contributor

The following code never prints out the statement

require 'manticore'
client = Manticore::Client.new
x = client.async.post("http://andrewvc.com") do |request|
  request.on_complete { puts "COMPLETE" }
end

Is .async broken at the moment?

@cheald
Copy link
Owner

cheald commented Aug 21, 2015

Oh, I think the doc may be out of date here. At one point, I switched the interface for async to basically be exactly the same as sync, just with the .async proxy.

When you pass a block to Client#post, it should becomes an implicit on_success block. If the request is not async, it causes the request to be evaluated immediately. Otherwise, it gets pushed into the async queue. They'll get flushed with you call Client#execute!.

This works as expected:

client = Manticore::Client.new
client.async.post("http://example.org")
  .on_success {|resp| p [:on_success, resp] }
  .on_complete { puts "Complete 1" }

client.async.post("http://example.org")
  .on_success {|resp| p [:on_success, resp] }
  .on_complete { puts "Complete 2" }

client.execute!

I'm going to wire up some tests to see what's going on, and will test the doc'd behavior and fix the doc if necessary.

@cheald
Copy link
Owner

cheald commented Aug 21, 2015

I've updated the doc to reflect that the old "pass a block to which the request is yielded" syntax is no longer valid. Additionally, I added some specs to response_spec which explicitly test the behavior of each of the callback handlers.

Your corrected example should be:

require 'manticore'
client = Manticore::Client.new
x = client.async.post("http://andrewvc.com")
      .on_complete { puts "COMPLETE" }
client.execute!

@cheald cheald closed this as completed Aug 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants