Skip to content

Commit 969574c

Browse files
authored
Merge pull request #1737 from TheBlueMatt/2022-09-future-trait
Add a bindings-only version of `Future::register_callback`
2 parents 3b7859f + 1beb3bb commit 969574c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lightning/src/util/wakers.rs

+12
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ pub struct Future {
163163
impl Future {
164164
/// Registers a callback to be called upon completion of this future. If the future has already
165165
/// completed, the callback will be called immediately.
166+
///
167+
/// (C-not exported) use the bindings-only `register_callback_fn` instead
166168
pub fn register_callback(&self, callback: Box<dyn FutureCallback>) {
167169
let mut state = self.state.lock().unwrap();
168170
if state.complete {
@@ -172,6 +174,16 @@ impl Future {
172174
state.callbacks.push(callback);
173175
}
174176
}
177+
178+
// C bindings don't (currently) know how to map `Box<dyn Trait>`, and while it could add the
179+
// following wrapper, doing it in the bindings is currently much more work than simply doing it
180+
// here.
181+
/// Registers a callback to be called upon completion of this future. If the future has already
182+
/// completed, the callback will be called immediately.
183+
#[cfg(c_bindings)]
184+
pub fn register_callback_fn<F: 'static + FutureCallback>(&self, callback: F) {
185+
self.register_callback(Box::new(callback));
186+
}
175187
}
176188

177189
mod std_future {

0 commit comments

Comments
 (0)