Skip to content

Commit

Permalink
refactor!: use &RetryConfig for retry overrides
Browse files Browse the repository at this point in the history
This is primarily in preparation for changing `Endpoint::retry_config`
to `Arc<RetryConfig>` so that it can be efficiently shared with
`Connection`s. It also quite likely that callers would have common
`RetryConfig` inside a static or const, so this may also avoid some
additional cloning on the caller end.

More generally, since we don't need ownership, asking for a reference
allows for more global efficiency since the caller gets to use a
reference if they have one.

BREAKING CHANGE: The `Endpoint::send_message_with` and
`Endpoint::try_send_message_with` methods now take `retries` as an
`Option<&RetryConfig>`, rather than `Option<RetryConfig>`.
  • Loading branch information
Chris Connelly authored and joshuef committed Sep 24, 2021
1 parent 2f0ec29 commit 70835ed
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,13 +456,13 @@ impl<I: ConnId> Endpoint<I> {
msg: Bytes,
dest: &SocketAddr,
priority: i32,
retries: Option<RetryConfig>,
retries: Option<&RetryConfig>,
) -> Result<(), Option<SendError>> {
if let Some((conn, guard)) = self.connection_pool.get_by_addr(dest).await {
trace!("Connection exists in the connection pool: {}", dest);
let connection = Connection::new(conn, guard);
retries
.unwrap_or(self.config.retry_config)
.unwrap_or(&self.config.retry_config)
.retry(|| async { Ok(connection.send_uni(msg.clone(), priority).await?) })
.await?;
Ok(())
Expand Down Expand Up @@ -522,11 +522,11 @@ impl<I: ConnId> Endpoint<I> {
msg: Bytes,
dest: &SocketAddr,
priority: i32,
retries: Option<RetryConfig>,
retries: Option<&RetryConfig>,
) -> Result<(), SendError> {
let connection = self.get_or_connect_to(dest).await?;
retries
.unwrap_or(self.config.retry_config)
.unwrap_or(&self.config.retry_config)
.retry(|| async { Ok(connection.send_uni(msg.clone(), priority).await?) })
.await?;

Expand Down

0 comments on commit 70835ed

Please sign in to comment.