From ca367f5d085cdc8e9a3e3bca4a846d840eea7c26 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Mon, 3 Apr 2023 20:15:04 +0000 Subject: [PATCH] Ensure `background-processor` exits after any sleep future says to If the user's sleep future passed to an async background processor only returns true for exiting once and then reverts back to false, we should exit anyway when we get a chance to. We do to this here by always ensuring we check the exit flag even when only polling sleep futures with no intent to (yet) exit. This is utilized in the tests added in the coming commit(s). --- lightning-background-processor/src/lib.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lightning-background-processor/src/lib.rs b/lightning-background-processor/src/lib.rs index 3dd099b49..da5f2acf8 100644 --- a/lightning-background-processor/src/lib.rs +++ b/lightning-background-processor/src/lib.rs @@ -554,7 +554,10 @@ where |fut: &mut SleepFuture, _| { let mut waker = dummy_waker(); let mut ctx = task::Context::from_waker(&mut waker); - core::pin::Pin::new(fut).poll(&mut ctx).is_ready() + match core::pin::Pin::new(fut).poll(&mut ctx) { + task::Poll::Ready(exit) => { should_break = exit; true }, + task::Poll::Pending => false, + } }, mobile_interruptable_platform) } -- 2.39.5