mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-01-19 05:43:55 +01:00
Use the user-provided SleepFuture
for interval checks in BP
`background-processor` does a number of jobs on various timers. Instead of doing those by interrogating `std::time::Instant`, this change swaps to using the existing user-provided sleep future. Fixes #1864.
This commit is contained in:
parent
d308710d4f
commit
e59b3847a3
@ -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<Target = PeerManager<Descriptor, CMH, RMH, OMH, L, UMH>> + Send + Sync,
|
||||
S: 'static + Deref<Target = SC> + Send + Sync,
|
||||
SC: WriteableScore<'a>,
|
||||
SleepFuture: core::future::Future<Output = bool>,
|
||||
SleepFuture: core::future::Future<Output = bool> + 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 {
|
||||
|
Loading…
Reference in New Issue
Block a user