1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
11 * A callback which is called when a [`Future`] completes.
13 * Note that this MUST NOT call back into LDK directly, it must instead schedule actions to be
14 * taken later. Rust users should use the [`std::future::Future`] implementation for [`Future`]
17 * Note that the [`std::future::Future`] implementation may only work for runtimes which schedule
18 * futures when they receive a wake, rather than immediately executing them.
20 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
21 public class FutureCallback extends CommonBase {
22 final bindings.LDKFutureCallback bindings_instance;
23 FutureCallback(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
24 private FutureCallback(bindings.LDKFutureCallback arg) {
25 super(bindings.LDKFutureCallback_new(arg));
26 this.ptrs_to.add(arg);
27 this.bindings_instance = arg;
29 @Override @SuppressWarnings("deprecation")
30 protected void finalize() throws Throwable {
31 if (ptr != 0) { bindings.FutureCallback_free(ptr); } super.finalize();
34 public static interface FutureCallbackInterface {
36 * The method which is called.
40 private static class LDKFutureCallbackHolder { FutureCallback held; }
41 public static FutureCallback new_impl(FutureCallbackInterface arg) {
42 final LDKFutureCallbackHolder impl_holder = new LDKFutureCallbackHolder();
43 impl_holder.held = new FutureCallback(new bindings.LDKFutureCallback() {
44 @Override public void call() {
46 Reference.reachabilityFence(arg);
49 return impl_holder.held;
52 * The method which is called.
55 bindings.FutureCallback_call(this.ptr);
56 Reference.reachabilityFence(this);