X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-background-processor%2Fsrc%2Flib.rs;h=b2ee865471c89f3ca1d537088c8e3425c9d4cbf8;hb=e59b3847a363afba5d30e1f1271341e3163f7591;hp=e93139bf0c2b0bf51fceeed432236d84a504498c;hpb=d308710d4f820e14eea68f95926bf1795a7bc843;p=rust-lightning diff --git a/lightning-background-processor/src/lib.rs b/lightning-background-processor/src/lib.rs index e93139bf..b2ee8654 100644 --- a/lightning-background-processor/src/lib.rs +++ b/lightning-background-processor/src/lib.rs @@ -36,7 +36,7 @@ use std::time::{Duration, Instant}; use std::ops::Deref; #[cfg(feature = "futures")] -use futures_util::{select_biased, future::FutureExt}; +use futures_util::{select_biased, future::FutureExt, task}; /// `BackgroundProcessor` takes care of tasks that (1) need to happen periodically to keep /// Rust-Lightning running properly, and (2) either can or should be run in the background. Its @@ -364,7 +364,7 @@ pub async fn process_events_async< PM: 'static + Deref> + Send + Sync, S: 'static + Deref + Send + Sync, SC: WriteableScore<'a>, - SleepFuture: core::future::Future, + SleepFuture: core::future::Future + core::marker::Unpin, Sleeper: Fn(Duration) -> SleepFuture >( persister: PS, event_handler: EventHandler, chain_monitor: M, channel_manager: CM, @@ -411,7 +411,12 @@ where false } } - }, |_| Instant::now(), |time: &Instant, dur| time.elapsed().as_secs() > dur) + }, |t| sleeper(Duration::from_secs(t)), + |fut: &mut SleepFuture, _| { + let mut waker = task::noop_waker(); + let mut ctx = task::Context::from_waker(&mut waker); + core::pin::Pin::new(fut).poll(&mut ctx).is_ready() + }) } impl BackgroundProcessor {