Skip to content

Commit

Permalink
Always log events
Browse files Browse the repository at this point in the history
  • Loading branch information
paolobarbolini authored Nov 15, 2023
1 parent f29fad9 commit be614fe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
5 changes: 4 additions & 1 deletion async-nats/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,10 @@ pub async fn connect_with_options<A: ToServerAddrs>(

task::spawn(async move {
while let Some(event) = events_rx.recv().await {
options.event_callback.call(event).await
tracing::info!("event: {}", event);
if let Some(event_callback) = &options.event_callback {
event_callback.call(event).await;
}
}
});

Expand Down
12 changes: 5 additions & 7 deletions async-nats/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub struct ConnectOptions {
pub(crate) ping_interval: Duration,
pub(crate) subscription_capacity: usize,
pub(crate) sender_capacity: usize,
pub(crate) event_callback: CallbackArg1<Event, ()>,
pub(crate) event_callback: Option<CallbackArg1<Event, ()>>,
pub(crate) inbox_prefix: String,
pub(crate) request_timeout: Option<Duration>,
pub(crate) retry_on_initial_connect: bool,
Expand Down Expand Up @@ -112,11 +112,7 @@ impl Default for ConnectOptions {
ping_interval: Duration::from_secs(60),
sender_capacity: 2048,
subscription_capacity: 1024 * 64,
event_callback: CallbackArg1::<Event, ()>(Box::new(move |event| {
Box::pin(async move {
tracing::info!("event: {}", event);
})
})),
event_callback: None,
inbox_prefix: "_INBOX".to_string(),
request_timeout: Some(Duration::from_secs(10)),
retry_on_initial_connect: false,
Expand Down Expand Up @@ -737,7 +733,9 @@ impl ConnectOptions {
F: Fn(Event) -> Fut + Send + Sync + 'static,
Fut: Future<Output = ()> + 'static + Send + Sync,
{
self.event_callback = CallbackArg1::<Event, ()>(Box::new(move |event| Box::pin(cb(event))));
self.event_callback = Some(CallbackArg1::<Event, ()>(Box::new(move |event| {
Box::pin(cb(event))
})));
self
}

Expand Down

0 comments on commit be614fe

Please sign in to comment.