From 1beb3bb4217d39df7ac1729eca2a188cae1ca958 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Fri, 23 Sep 2022 21:08:26 +0000 Subject: [PATCH] Add a bindings-only version of `Future::register_callback` While we could, in theory, add support to the bindings logic to map `Box`, there isn't a whole lot of use doing so when its incredibly trivial to do directly. This adds a trivial wrapper around `Future::register_callback` that is only built in bindings and which is linked in the `register_callback` docs for visibility. --- lightning/src/util/wakers.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lightning/src/util/wakers.rs b/lightning/src/util/wakers.rs index e49c832ef..166771948 100644 --- a/lightning/src/util/wakers.rs +++ b/lightning/src/util/wakers.rs @@ -163,6 +163,8 @@ pub struct Future { impl Future { /// Registers a callback to be called upon completion of this future. If the future has already /// completed, the callback will be called immediately. + /// + /// (C-not exported) use the bindings-only `register_callback_fn` instead pub fn register_callback(&self, callback: Box) { let mut state = self.state.lock().unwrap(); if state.complete { @@ -172,6 +174,16 @@ impl Future { state.callbacks.push(callback); } } + + // C bindings don't (currently) know how to map `Box`, and while it could add the + // following wrapper, doing it in the bindings is currently much more work than simply doing it + // here. + /// Registers a callback to be called upon completion of this future. If the future has already + /// completed, the callback will be called immediately. + #[cfg(c_bindings)] + pub fn register_callback_fn(&self, callback: F) { + self.register_callback(Box::new(callback)); + } } mod std_future { -- 2.39.5