Skip to content

Commit a041fc9

Browse files
committed
Replace futures select with our own select enum to fix MSRV
`futures` recently broke our MSRV by bumping the `syn` major version in a patch release. This makes it impractical for us to use, instead here we replace the usage of its `select_biased` macro with a trivial enum. Given its simplicity we likely should have done this without ever taking the dependency.
1 parent 387ae75 commit a041fc9

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

lightning-background-processor/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ default = ["std"]
2323
bitcoin = { version = "0.29.0", default-features = false }
2424
lightning = { version = "0.0.114", path = "../lightning", default-features = false }
2525
lightning-rapid-gossip-sync = { version = "0.0.114", path = "../lightning-rapid-gossip-sync", default-features = false }
26-
futures-util = { version = "0.3", default-features = false, features = ["async-await-macro"], optional = true }
26+
futures-util = { version = "0.3", default-features = false, optional = true }
2727

2828
[dev-dependencies]
2929
lightning = { version = "0.0.114", path = "../lightning", features = ["_test_utils"] }

lightning-background-processor/src/lib.rs

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,40 @@ macro_rules! define_run_body {
384384
} }
385385
}
386386

387+
#[cfg(feature = "futures")]
388+
use core::future::Future;
389+
#[cfg(feature = "futures")]
390+
use core::task::Poll;
391+
#[cfg(feature = "futures")]
392+
use core::pin::Pin;
393+
#[cfg(feature = "futures")]
394+
use core::marker::Unpin;
395+
#[cfg(feature = "futures")]
396+
struct Selecter<A: Future<Output=()> + Unpin, B: Future<Output=bool> + Unpin> {
397+
a: A,
398+
b: B,
399+
}
400+
#[cfg(feature = "futures")]
401+
enum SelecterOutput {
402+
A, B(bool),
403+
}
404+
405+
#[cfg(feature = "futures")]
406+
impl<A: Future<Output=()> + Unpin, B: Future<Output=bool> + Unpin> Future for Selecter<A, B> {
407+
type Output = SelecterOutput;
408+
fn poll(mut self: Pin<&mut Self>, ctx: &mut core::task::Context<'_>) -> Poll<SelecterOutput> {
409+
match Pin::new(&mut self.a).poll(ctx) {
410+
Poll::Ready(()) => { return Poll::Ready(SelecterOutput::A); },
411+
Poll::Pending => {},
412+
}
413+
match Pin::new(&mut self.b).poll(ctx) {
414+
Poll::Ready(res) => { return Poll::Ready(SelecterOutput::B(res)); },
415+
Poll::Pending => {},
416+
}
417+
Poll::Pending
418+
}
419+
}
420+
387421
/// Processes background events in a future.
388422
///
389423
/// `sleeper` should return a future which completes in the given amount of time and returns a
@@ -470,9 +504,13 @@ where
470504
chain_monitor, chain_monitor.process_pending_events_async(async_event_handler).await,
471505
channel_manager, channel_manager.process_pending_events_async(async_event_handler).await,
472506
gossip_sync, peer_manager, logger, scorer, should_break, {
473-
select_biased! {
474-
_ = channel_manager.get_persistable_update_future().fuse() => true,
475-
exit = sleeper(Duration::from_millis(100)).fuse() => {
507+
let fut = Selecter {
508+
a: channel_manager.get_persistable_update_future(),
509+
b: sleeper(Duration::from_millis(100)),
510+
};
511+
match fut.await {
512+
SelecterOutput::A => true,
513+
SelecterOutput::B(exit) => {
476514
should_break = exit;
477515
false
478516
}

0 commit comments

Comments
 (0)