diff --git a/daemon/src/maker.rs b/daemon/src/maker.rs index 94fe34b..4a82986 100644 --- a/daemon/src/maker.rs +++ b/daemon/src/maker.rs @@ -42,6 +42,7 @@ mod seed; mod send_to_socket; mod setup_contract; mod to_sse_event; +mod tokio_ext; mod wallet; mod wallet_sync; mod wire; diff --git a/daemon/src/oracle.rs b/daemon/src/oracle.rs index 991cabf..2810e5d 100644 --- a/daemon/src/oracle.rs +++ b/daemon/src/oracle.rs @@ -1,6 +1,7 @@ use crate::actors::log_error; use crate::model::cfd::{Cfd, CfdState}; use crate::model::BitMexPriceEventId; +use crate::tokio_ext; use anyhow::{Context, Result}; use async_trait::async_trait; use cfd_protocol::secp256k1_zkp::{schnorrsig, SecretKey}; @@ -111,7 +112,7 @@ where for event_id in self.pending_announcements.iter().cloned() { let this = this.clone(); - tokio::spawn(async move { + tokio_ext::spawn_fallible(async move { let url = event_id.to_olivia_url(); tracing::debug!("Fetching announcement for {}", event_id); diff --git a/daemon/src/taker.rs b/daemon/src/taker.rs index 9ba4646..7dfae56 100644 --- a/daemon/src/taker.rs +++ b/daemon/src/taker.rs @@ -42,6 +42,7 @@ mod send_to_socket; mod setup_contract; mod taker_cfd; mod to_sse_event; +mod tokio_ext; mod wallet; mod wallet_sync; mod wire; diff --git a/daemon/src/tokio_ext.rs b/daemon/src/tokio_ext.rs new file mode 100644 index 0000000..a0c4f0b --- /dev/null +++ b/daemon/src/tokio_ext.rs @@ -0,0 +1,14 @@ +use std::fmt; +use std::future::Future; + +pub fn spawn_fallible(future: F) +where + F: Future> + Send + 'static, + E: fmt::Display, +{ + tokio::spawn(async move { + if let Err(e) = future.await { + tracing::warn!("Task failed: {:#}", e); + } + }); +}