Skip to content

Clarifying adapter usage vs "plain Async" #55

@balvig

Description

@balvig

Sorry to use GitHub issues for a question (happy to turn this into a documentation PR if applicable!), but I'm struggling to understand the difference between using this adapter with Faraday, vs using "plain" https://github.com/socketry/async with Faraday.

The in_parallel documentation shows the following example:

Async do
  response1 = Async{adapter.get("/index")}
  response2 = Async{adapter.get("/index")}
  response3 = Async{adapter.get("/index")}
  
  puts response1.wait.body # => "Hello World"
  puts response2.wait.body # => "Hello World"
  puts response3.wait.body # => "Hello World"
end

I'm having trouble understanding how this relates to the faraday adapter and what the difference is from using just https://github.com/socketry/async?

Put differently, what is the difference between these three examples?

1. Set default_adapter to async_http

Faraday.default_adapter = :async_http

response1 = adapter.get("/index")
response2 = adapter.get("/index")

puts response1.body
puts response2.body

2. Set default_adapter to async_http + use Async block

Faraday.default_adapter = :async_http

Async do
  response1 = Async{adapter.get("/index")}
  response2 = Async{adapter.get("/index")}

  puts response1.wait.body
  puts response2.wait.body
end

3. Use regular default_adapter + use Async block

Async do
  response1 = Async{adapter.get("/index")}
  response2 = Async{adapter.get("/index")}

  puts response1.wait.body
  puts response2.wait.body
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions