Skip to content

Commit f6804eb

Browse files
committed
feat: add the option to set a timeout in the BpxClientBuilder
Related to #50
1 parent a0fd38e commit f6804eb

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

client/src/lib.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ use serde_json::Value;
5454
use std::{
5555
borrow::Cow,
5656
collections::BTreeMap,
57-
time::{SystemTime, UNIX_EPOCH},
57+
time::{Duration, SystemTime, UNIX_EPOCH},
5858
};
5959

6060
pub mod error;
@@ -335,6 +335,7 @@ pub struct BpxClientBuilder {
335335
ws_url: Option<String>,
336336
secret: Option<String>,
337337
headers: Option<BpxHeaders>,
338+
timeout: Option<u64>,
338339
}
339340

340341
impl BpxClientBuilder {
@@ -395,6 +396,19 @@ impl BpxClientBuilder {
395396
self
396397
}
397398

399+
/// Sets a custom Timeout for the underlying http client
400+
/// If not set, a default of 30 seconds is used.
401+
///
402+
/// # Arguments
403+
/// * `timeout` - The timeout in seconds
404+
///
405+
/// # Returns
406+
/// * `Self` - The updated builder instance
407+
pub fn timeout(mut self, timeout: u64) -> Self {
408+
self.timeout = Some(timeout);
409+
self
410+
}
411+
398412
/// Builds the `BpxClient` instance with the configured parameters.
399413
///
400414
/// # Returns
@@ -440,6 +454,7 @@ impl BpxClientBuilder {
440454
client: reqwest::Client::builder()
441455
.user_agent(API_USER_AGENT)
442456
.default_headers(header_map)
457+
.timeout(Duration::from_secs(self.timeout.unwrap_or(30)))
443458
.build()?,
444459
};
445460

0 commit comments

Comments
 (0)