add create_geyser_autoconnection_task_with_mpsc
This commit is contained in:
parent
66c4256438
commit
a6ab686fa4
|
@ -42,20 +42,17 @@ pub fn create_geyser_autoconnection_task(
|
||||||
(abort_handle, receiver_channel)
|
(abort_handle, receiver_channel)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// connect to grpc source performing autoconect if required,
|
/// connect to grpc source performing autoconnect if required,
|
||||||
/// returns mpsc channel; task will abort on fatal error
|
/// returns mpsc channel; task will abort on fatal error
|
||||||
///
|
/// will shut down when receiver is dropped
|
||||||
/// implementation hints:
|
|
||||||
/// * no panic/unwrap
|
|
||||||
/// * do not use "?"
|
|
||||||
/// * do not "return" unless you really want to abort the task
|
|
||||||
pub fn create_geyser_autoconnection_task_with_mpsc(
|
pub fn create_geyser_autoconnection_task_with_mpsc(
|
||||||
grpc_source: GrpcSourceConfig,
|
grpc_source: GrpcSourceConfig,
|
||||||
subscribe_filter: SubscribeRequest,
|
subscribe_filter: SubscribeRequest,
|
||||||
mpsc_sender: tokio::sync::mpsc::Sender<Message>,
|
mpsc_downstream: tokio::sync::mpsc::Sender<Message>,
|
||||||
) -> AbortHandle {
|
) -> AbortHandle {
|
||||||
// read this for argument: http://www.randomhacks.net/2019/03/08/should-rust-channels-panic-on-send/
|
// read this for argument: http://www.randomhacks.net/2019/03/08/should-rust-channels-panic-on-send/
|
||||||
|
|
||||||
|
// task will be aborted when downstream receiver gets dropped
|
||||||
let jh_geyser_task = tokio::spawn(async move {
|
let jh_geyser_task = tokio::spawn(async move {
|
||||||
let mut state = ConnectionState::NotConnected(0);
|
let mut state = ConnectionState::NotConnected(0);
|
||||||
let mut messages_forwarded = 0;
|
let mut messages_forwarded = 0;
|
||||||
|
@ -231,7 +228,7 @@ pub fn create_geyser_autoconnection_task_with_mpsc(
|
||||||
Duration::from_millis(500)
|
Duration::from_millis(500)
|
||||||
};
|
};
|
||||||
let started_at = Instant::now();
|
let started_at = Instant::now();
|
||||||
match mpsc_sender
|
match mpsc_downstream
|
||||||
.send_timeout(
|
.send_timeout(
|
||||||
Message::GeyserSubscribeUpdate(Box::new(update_message)),
|
Message::GeyserSubscribeUpdate(Box::new(update_message)),
|
||||||
warning_threshold,
|
warning_threshold,
|
||||||
|
@ -255,7 +252,7 @@ pub fn create_geyser_autoconnection_task_with_mpsc(
|
||||||
Err(SendTimeoutError::Timeout(the_message)) => {
|
Err(SendTimeoutError::Timeout(the_message)) => {
|
||||||
warn!("downstream receiver did not pick up message for {}ms - keep waiting", warning_threshold.as_millis());
|
warn!("downstream receiver did not pick up message for {}ms - keep waiting", warning_threshold.as_millis());
|
||||||
|
|
||||||
match mpsc_sender.send(the_message).await {
|
match mpsc_downstream.send(the_message).await {
|
||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
messages_forwarded += 1;
|
messages_forwarded += 1;
|
||||||
trace!(
|
trace!(
|
||||||
|
|
Loading…
Reference in New Issue