add support for parallel json parsing

This commit is contained in:
rick 2009-12-10 09:06:28 -08:00
parent 9b0d33fa85
commit 43884ec7d9
3 changed files with 18 additions and 5 deletions

View File

@ -23,9 +23,11 @@ experiments in a rest api lib
resp = conn.get("/sake.json")
resp.body # => %({"name":"Sake"})
# uses Typhoeus, performs requests in parallel
# uses Typhoeus, Yajl parsing, performs requests in parallel
conn = Faraday::Connection.new("http://sushi.com")
conn.extend Faraday::Adapter::Typhoeus
conn.response_class = Faraday::Response::DelayedYajlResponse
resp1, resp2 = nil, nil
conn.in_parallel do
resp1 = conn.get("/sake.json")
resp2 = conn.get("/unagi.json")
@ -34,8 +36,8 @@ experiments in a rest api lib
resp1.body # => nil
resp2.body # => nil
end
resp1.body # => %({"name":"Sake"})
resp2.body # => %({"name":"Unagi"})
resp1.body # => {"name": "Sake"}
resp2.body # => {"name": "Unagi"}
== Testing

View File

@ -0,0 +1,10 @@
require 'yajl'
module Faraday
class Response
class DelayedYajlResponse < YajlResponse
def content
self
end
end
end
end

View File

@ -2,7 +2,8 @@ require 'yajl'
module Faraday
class Response
class YajlResponse < Response
attr_reader :content
attr_reader :body
alias content body
def initialize(headers = nil, body = nil)
super
@ -22,7 +23,7 @@ module Faraday
end
def object_parsed(obj)
@content = obj
@body = obj
end
end
end