Skip to content

Commit

Permalink
clarify await_or_exit behavior on channel close
Browse files Browse the repository at this point in the history
  • Loading branch information
grooviegermanikus committed Apr 29, 2024
1 parent 1245d8b commit dd78804
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/grpc_subscription_autoreconnect_tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::time::Duration;
use tokio::sync::mpsc::error::SendTimeoutError;
use tokio::sync::mpsc::Receiver;
use tokio::sync::broadcast;
use tokio::sync::broadcast::error::RecvError;
use tokio::task::JoinHandle;
use tokio::time::{sleep, timeout, Instant};
use yellowstone_grpc_client::{GeyserGrpcClient, GeyserGrpcClientError};
Expand Down Expand Up @@ -379,16 +380,27 @@ enum MaybeExit<T> {
Exit,
}

async fn await_or_exit<F, E>(future: F, exit_notify: E) -> MaybeExit<F::Output>
async fn await_or_exit<F, E, T>(future: F, exit_notify: E) -> MaybeExit<F::Output>
where
F: Future,
E: Future,
E: Future<Output = Result<T, RecvError>>,
{
tokio::select! {
res = future => {
MaybeExit::Continue(res)
},
_ = exit_notify => {
res = exit_notify => {
match res {
Ok(_) => {
debug!("exit on signal");
}
Err(RecvError::Lagged(_)) => {
warn!("exit on signal (lag)");
}
Err(RecvError::Closed) => {
warn!("exit on signal (channel close)");
}
}
MaybeExit::Exit
}
}
Expand Down

0 comments on commit dd78804

Please sign in to comment.