Browse Source

Introduce drop-in replacement for tokio::spawn that logs errors

Otherwise, any errors occurring within these tasks are silently
ignored.
refactor/no-log-handler
Thomas Eizinger 3 years ago
parent
commit
013d9f2ef0
No known key found for this signature in database GPG Key ID: 651AC83A6C6C8B96
  1. 1
      daemon/src/maker.rs
  2. 3
      daemon/src/oracle.rs
  3. 1
      daemon/src/taker.rs
  4. 14
      daemon/src/tokio_ext.rs

1
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;

3
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);

1
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;

14
daemon/src/tokio_ext.rs

@ -0,0 +1,14 @@
use std::fmt;
use std::future::Future;
pub fn spawn_fallible<F, E>(future: F)
where
F: Future<Output = Result<(), E>> + Send + 'static,
E: fmt::Display,
{
tokio::spawn(async move {
if let Err(e) = future.await {
tracing::warn!("Task failed: {:#}", e);
}
});
}
Loading…
Cancel
Save