lib/vacuum/em.rb in vacuum-0.1.2 vs lib/vacuum/em.rb in vacuum-0.1.3

- old
+ new

@@ -3,21 +3,19 @@ module Vacuum class Request # Performs an async request. # + # @param err [Proc] A callback to be executed if request fails # @yield Passes response to given block - def aget(&blk) + def aget(err = nil, &blk) http = EM::HttpRequest.new(url).get - http.callback { blk.call _response(http) } - http.errback { blk.call _response(http) } - - nil - end - - private - - def _response(http) - Response.new(http.response, http.response_header.status) + # @todo Consider using a SAX parser that can work on the chunks as they + # come in? + # http.stream { |chunk| parse chunk } + http.callback do + yield Response.new http.response, http.response_header.status + end + http.errback &err if err end end end