Skip to content

provide async api everywhere we provide a synchronous one: Query#get, Object#save, etc. #94

Open
@ericcj

Description

@ericcj

we could split out a version of this gem as an eventmachine protocol, and might want to do that anyways, but it would be nice to offer an async api without requiring they be using eventmachine. faraday appears to be the best way to do that, so we would need to get #88 merged then implement asynchronous versions of the api like:

query.get_async do |results|

access results Array here like you would from the synchronously returned one

end

these would use a Faraday middleware to call the block you pass as in http://blog.carbonfive.com/2013/03/15/parallel-http-requests-with-faraday-and-typhoeus/ with us passing the block through env via:

@session.get(...) do |request|
request.options["pf_block"] = block
end

and could therefore be nested inside the parallel faraday api as follows:

foos = nil
bars = nil

Parse.client.session.in_parallel do 
  Parse::Query.new("Foo").get_async do |f|
    foos = f
  end

  Parse::Query.new("Bar").get_async do |b|
    bars = b
  end
end

puts foos + bars

it appears that nesting async calls within the callbacks of others would work

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions