Skip to content

Commit

Permalink
1. Updated sse proxy config to builder patter..
Browse files Browse the repository at this point in the history
  • Loading branch information
asladeofgreen committed Jan 20, 2025
1 parent 7f6897f commit 928658c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
5 changes: 2 additions & 3 deletions crates/node-sse/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ use thiserror::Error;

#[derive(Error, Debug)]
pub enum ClientError {
#[error("Failed to send command to core: {0}")]
CommandDispatchError(#[from] tokio::sync::mpsc::error::SendError<CoreCommand>),

// #[error("Failed to send command to core: {0}")]
// CommandDispatchError(#[from] tokio::sync::mpsc::error::SendError<CoreCommand>),
#[error("Failed to receive command from core: {0}")]
CommandReceiveError(#[from] tokio::sync::oneshot::error::RecvError),

Expand Down
47 changes: 28 additions & 19 deletions crates/node-sse/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,7 @@ impl Proxy {
}

impl ProxyConfig {
pub fn new(
backoff_factor: u32,
delay_on_retry: Duration,
max_delay_between_reconnects: Duration,
reconnect_on_error: bool,
retry_initial_connection: bool,
url: String,
) -> Self {
Self {
backoff_factor,
delay_on_retry,
max_delay_between_reconnects,
reconnect_on_error,
retry_initial_connection,
url,
}
}

pub fn new_from_defaults(url: String) -> Self {
pub fn new(url: String) -> Self {
Self {
backoff_factor: 2,
delay_on_retry: Duration::from_secs(2),
Expand All @@ -71,3 +53,30 @@ impl ProxyConfig {
}
}
}

impl ProxyConfig {
pub fn backoff_factor<'a>(&'a mut self, value: u32) -> &'a mut ProxyConfig {
self.backoff_factor = value;
self
}

pub fn delay_on_retry<'a>(&'a mut self, value: Duration) -> &'a mut ProxyConfig {
self.delay_on_retry = value;
self
}

pub fn max_delay_between_reconnects<'a>(&'a mut self, value: Duration) -> &'a mut ProxyConfig {
self.max_delay_between_reconnects = value;
self
}

pub fn reconnect_on_error<'a>(&'a mut self, value: bool) -> &'a mut ProxyConfig {
self.reconnect_on_error = value;
self
}

pub fn retry_initial_connection<'a>(&'a mut self, value: bool) -> &'a mut ProxyConfig {
self.retry_initial_connection = value;
self
}
}

0 comments on commit 928658c

Please sign in to comment.