Skip to content

Add a bindings-only version of Future::register_callback #1737

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lightning/src/util/wakers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn FutureCallback>) {
let mut state = self.state.lock().unwrap();
if state.complete {
Expand All @@ -172,6 +174,16 @@ impl Future {
state.callbacks.push(callback);
}
}

// C bindings don't (currently) know how to map `Box<dyn Trait>`, 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<F: 'static + FutureCallback>(&self, callback: F) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I can't think of a better name, to be honest. It is a shame to have the discrepancy in naming between bindings/using Rust directly though, but this change is pretty simple and so probably best for now.

self.register_callback(Box::new(callback));
}
}

mod std_future {
Expand Down