Skip to content

Commit 0d51492

Browse files
authored
feat: add the option to set a timeout in the BpxClientBuilder (#92)
Related to #50
1 parent 4495822 commit 0d51492

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

client/src/lib.rs

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

6161
pub mod error;
@@ -384,6 +384,7 @@ pub struct BpxClientBuilder {
384384
ws_url: Option<String>,
385385
secret: Option<String>,
386386
headers: Option<BpxHeaders>,
387+
timeout: Option<u64>,
387388
}
388389

389390
impl BpxClientBuilder {
@@ -444,6 +445,19 @@ impl BpxClientBuilder {
444445
self
445446
}
446447

448+
/// Sets a custom Timeout for the underlying http client
449+
/// If not set, a default of 30 seconds is used.
450+
///
451+
/// # Arguments
452+
/// * `timeout` - The timeout in seconds
453+
///
454+
/// # Returns
455+
/// * `Self` - The updated builder instance
456+
pub fn timeout(mut self, timeout: u64) -> Self {
457+
self.timeout = Some(timeout);
458+
self
459+
}
460+
447461
/// Builds the `BpxClient` instance with the configured parameters.
448462
///
449463
/// # Returns
@@ -489,6 +503,7 @@ impl BpxClientBuilder {
489503
client: reqwest::Client::builder()
490504
.user_agent(API_USER_AGENT)
491505
.default_headers(header_map)
506+
.timeout(Duration::from_secs(self.timeout.unwrap_or(30)))
492507
.build()?,
493508
};
494509

0 commit comments

Comments
 (0)