Skip to content

Commit 867b807

Browse files
committed
Allow setting recv_timeout when sending request
1 parent d8e96bb commit 867b807

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/gleam/hackney.gleam

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,33 @@ fn ffi_send(
2121
b: String,
2222
c: List(http.Header),
2323
d: BytesBuilder,
24+
e: Int
2425
) -> Result(Response(BitArray), Error)
2526

2627
// TODO: test
2728
pub fn send_bits(
2829
request: Request(BytesBuilder),
30+
timeout: Int
2931
) -> Result(Response(BitArray), Error) {
3032
use response <- result.then(
3133
request
3234
|> request.to_uri
3335
|> uri.to_string
34-
|> ffi_send(request.method, _, request.headers, request.body),
36+
|> ffi_send(request.method, _, request.headers, request.body, timeout),
3537
)
3638
let headers = list.map(response.headers, normalise_header)
3739
Ok(Response(..response, headers: headers))
3840
}
3941

4042
pub fn send(req: Request(String)) -> Result(Response(String), Error) {
43+
send_with_timeout(req, 8000)
44+
}
45+
46+
pub fn send_with_timeout(req: Request(String), timeout: Int) -> Result(Response(String), Error) {
4147
use resp <- result.then(
4248
req
4349
|> request.map(bytes_builder.from_string)
44-
|> send_bits,
50+
|> send_bits(timeout),
4551
)
4652

4753
case bit_array.to_string(resp.body) {

0 commit comments

Comments
 (0)