Skip to content

Commit

Permalink
Merge pull request #238 from josevalim/patch-1
Browse files Browse the repository at this point in the history
Do not use streams with async_request
  • Loading branch information
sneako authored Jul 26, 2023
2 parents 53e4034 + 0ee3b7c commit d83efa7
Showing 1 changed file with 12 additions and 23 deletions.
35 changes: 12 additions & 23 deletions lib/finch.ex
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,11 @@ defmodule Finch do
Sends an HTTP request asynchronously, returning a request reference.
If the request is sent using HTTP1, an extra process is spawned to
consume messages from the underlying socket. If you wish to maximize
request rate, a strategy using `request/3` or `stream/5` should be
used to avoid this overhead.
consume messages from the underlying socket. The messages are sent
to the current process as soon as they arrive, as a firehose. If
you wish to maximize request rate or have more control over how
messages are streamed, a strategy using `request/3` or `stream/5`
should be used instead.
## Receiving the response
Expand All @@ -411,26 +413,13 @@ defmodule Finch do
## Example
iex> Stream.resource(
...> fn ->
...> Finch.build(:get, "https://httpbin.org/stream/5")
...> |> Finch.async_request(MyFinch)
...> end,
...> fn ref ->
...> receive do
...> {^ref, :done} -> {:halt, ref}
...> {^ref, response} -> {[response], ref}
...> end
...> end,
...> fn _ref -> :ok end
...> ) |> Enum.to_list()
[
{:status, 200},
{:headers, [...]},
{:data, "..."},
...
:done
]
iex> req = Finch.build(:get, "https://httpbin.org/stream/5")
iex> ref = Finch.async_request(req, MyFinch)
iex> flush()
{ref, {:status, 200}}
{ref, {:headers, [...]}}
{ref, {:data, "..."}}
{ref, :done}
## Options
Expand Down

0 comments on commit d83efa7

Please sign in to comment.