fregas
fregas

Reputation: 3250

Ruby HttpClient async

Hello stack overflow people.

Does someone know of a code example to make the ruby httpclient do an async post? It has a method but it looks like it just gives you a connection back you have to keep checking, which I assume would still be blocking. I did not see a way to "fire and forget" or just pass a method that it could call later in a separate thread while the rest of my code kept running.

thanks, craig

Upvotes: 0

Views: 1513

Answers (1)

kaspar
kaspar

Reputation: 114

This sounds like you're programming in evented style. Maybe you are even using eventmachine? You don't say so, but in the case you do, this project: https://github.com/eventmachine/em-http-request will let you do something close:

EventMachine.run {
  http = EventMachine::HttpRequest.new('http://127.0.0.1/').get :query => {'keyname' => 'value'}

  http.callback {
    p http.response_header.status
    p http.response_header
    p http.response

    EventMachine.stop
  }
}

Upvotes: 1

Related Questions