Skip to content

Commit 92f3c8c

Browse files
committed
feat: Add timeout parameter to HTTP.Promise.await
- Added optional timeout parameter to await/2 function - Default timeout remains :infinity for backward compatibility - Updated documentation to reflect new parameter - Updated @SPEC to include timeout types
1 parent 4ef2ae5 commit 92f3c8c

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

lib/http/promise.ex

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,18 @@ defmodule HTTP.Promise do
1313
@doc """
1414
Awaits the completion of the HTTP promise.
1515
16+
Arguments:
17+
- `promise`: The `HTTP.Promise` instance to await.
18+
- `timeout`: Optional timeout in milliseconds or `:infinity`. Defaults to `:infinity`.
19+
1620
Returns:
1721
- `%HTTP.Response{}` on successful completion.
1822
- `{:error, reason}` if the request fails or is aborted.
23+
- `{:error, :timeout}` if the timeout is reached.
1924
"""
20-
@spec await(t()) :: HTTP.Response.t() | {:error, term()}
21-
def await(%__MODULE__{task: task}) do
22-
Task.await(task)
25+
@spec await(t(), timeout :: non_neg_integer() | :infinity) :: HTTP.Response.t() | {:error, term()}
26+
def await(%__MODULE__{task: task}, timeout \\ :infinity) do
27+
Task.await(task, timeout)
2328
end
2429

2530
@doc """

0 commit comments

Comments
 (0)