Skip to content

Commit 7102a6c

Browse files
committed
Improved error handling
1 parent 2535277 commit 7102a6c

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

concurrency/src/tasks/gen_server.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use crate::{
44
error::GenServerError,
55
tasks::InitResult::{NoSuccess, Success},
66
};
7-
use futures::future::FutureExt as _;
7+
use core::pin::pin;
8+
use futures::future::{self, FutureExt as _};
89
use spawned_rt::{
910
tasks::{self as rt, mpsc, oneshot, timeout, CancellationToken, JoinHandle},
1011
threads,
@@ -346,15 +347,15 @@ where
346347
{
347348
let cancelation_token = handle.cancellation_token();
348349
let mut handle_clone = handle.clone();
349-
let join_handle = spawned_rt::tasks::spawn(async move {
350-
tracing::info!("Ctrl+C listener started");
351-
let is_cancelled = core::pin::pin!(cancelation_token.cancelled());
352-
let signal = core::pin::pin!(future);
353-
match futures::future::select(is_cancelled, signal).await {
354-
futures::future::Either::Left(_) => tracing::error!("GenServer stopped"),
355-
futures::future::Either::Right(_) => {
356-
tracing::info!("Sending shutdown to PeerTable Server");
357-
handle_clone.cast(message).await.unwrap();
350+
let join_handle = rt::spawn(async move {
351+
let is_cancelled = pin!(cancelation_token.cancelled());
352+
let signal = pin!(future);
353+
match future::select(is_cancelled, signal).await {
354+
future::Either::Left(_) => tracing::error!("GenServer stopped"),
355+
future::Either::Right(_) => {
356+
if let Err(e) = handle_clone.cast(message).await {
357+
tracing::error!("Failed to send message: {e:?}")
358+
}
358359
}
359360
}
360361
});

0 commit comments

Comments
 (0)