HTTP.AbortController (http_fetch v0.1.0)

Provides request cancellation functionality similar to the browser's AbortController.

Summary

Functions

Aborts the associated HTTP request. Sends a stop signal to :httpc if a request is active and not already aborted.

Checks if the controller has been aborted.

Returns a specification to start this module under a supervisor.

Creates a new AbortController instance. Returns the PID of the agent, which acts as the controller reference.

Sets the :httpc request_id for the given controller. This links the controller to an active request.

Starts a new AbortController agent. Returns {:ok, pid} of the agent.

Types

state()

@type state() :: %{
  request_id: pid() | nil,
  signal_ref: reference(),
  aborted: boolean()
}

Functions

abort(controller_pid)

@spec abort(pid()) :: :ok

Aborts the associated HTTP request. Sends a stop signal to :httpc if a request is active and not already aborted.

aborted?(controller_pid)

@spec aborted?(pid()) :: boolean()

Checks if the controller has been aborted.

child_spec(arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

new()

@spec new() :: pid()

Creates a new AbortController instance. Returns the PID of the agent, which acts as the controller reference.

set_request_id(controller_pid, request_id)

@spec set_request_id(pid(), pid()) :: :ok

Sets the :httpc request_id for the given controller. This links the controller to an active request.

start_link(initial_state \\ %{request_id: nil, signal_ref: make_ref(), aborted: false})

@spec start_link(state()) :: {:ok, pid()}

Starts a new AbortController agent. Returns {:ok, pid} of the agent.