View Source erqwest_async (erqwest v0.2.5)
Link to this section Summary
Functions
Cancel an asynchronous request at any stage. A reply will always still be sent, either
{error, #{code := cancelled}}
, another error
or a reply
depending on the state of the connection. Has no effect if the request has already completed or was already cancelled.Complete sending the request body. The message flow continues as described for
req/4
, ie. the next message will be reply
or error
.Read a chunk of the response body, waiting for at most
period
ms or until at least length
bytes have been read. Note that more than length
bytes can be returned. length
defaults to 8 MB if omitted, and period
to infinity
. Note that more than length
bytes can be returned. Replies with {erqwest_response, Ref, chunk, Data}
, {erqwest_response, Ref, fin, Data}
or {erqwest_response, Ref, error, erqwest:err()}`. A `fin
or error
response will be the final message.Make an asynchronous request.
Asynchronously stream a chunk of the request body. Replies with
{erqwest_response, Ref, next}
when the connection is ready to receive more data. Replies with {erqwest_response, Ref, error, erqwest:err()}
if something goes wrong, or {erqwest_response, Ref, reply, erqwest:resp()}
if the server has already decided to reply. Call finish_send/1
when the request body is complete.Link to this section Types
Specs
handle()
Link to this section Functions
Specs
cancel(handle()) -> ok.
{error, #{code := cancelled}}
, another error
or a reply
depending on the state of the connection. Has no effect if the request has already completed or was already cancelled.
Specs
finish_send(handle()) -> ok.
req/4
, ie. the next message will be reply
or error
.
Specs
read(handle(), erqwest:read_opts()) -> ok.
period
ms or until at least length
bytes have been read. Note that more than length
bytes can be returned. length
defaults to 8 MB if omitted, and period
to infinity
. Note that more than length
bytes can be returned. Replies with {erqwest_response, Ref, chunk, Data}
, {erqwest_response, Ref, fin, Data}
or {erqwest_response, Ref, error, erqwest:err()}`. A `fin
or error
response will be the final message.
Specs
req(erqwest:client() | atom(), pid(), any(), erqwest:req_opts()) -> handle().
Make an asynchronous request.
A Response will be sent to Pid
as follows:
* If body
is stream
, and the request was successfully initated, {erqwest_response, Ref, next}
. See send/2
and finish_send/1
for how to respond. Alternatively {erqwest_response, Ref, error, erqwest:err()}
.
* If body
is omitted or is of type iodata()
, {erqwest_response, Ref, reply, erqwest:resp()}
or {erqwest_response, Ref, error, erqwest:err()}
.
* If response_body
is stream
, erqwest:resp()
will contain a handle which should be passed to read/2
. Alternatively, call cancel/1
if you do not intend to consume the body.
An error
response is _always_ the final response. If streaming is not used, a single reply is guaranteed.
Specs
send(handle(), iodata()) -> ok.
{erqwest_response, Ref, next}
when the connection is ready to receive more data. Replies with {erqwest_response, Ref, error, erqwest:err()}
if something goes wrong, or {erqwest_response, Ref, reply, erqwest:resp()}
if the server has already decided to reply. Call finish_send/1
when the request body is complete.