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 * Destroys the object, freeing associated resources. After this call, any access
35 * to this object may result in a SEGFAULT or worse.
37 * You should generally NEVER call this method. You should let the garbage collector
38 * do this for you when it finalizes objects. However, it may be useful for types
39 * which represent locks and should be closed immediately to avoid holding locks
42 public void destroy() {
43 if (ptr != 0) { bindings.FutureCallback_free(ptr); }
46 public static interface FutureCallbackInterface {
48 * The method which is called.
52 private static class LDKFutureCallbackHolder { FutureCallback held; }
53 public static FutureCallback new_impl(FutureCallbackInterface arg) {
54 final LDKFutureCallbackHolder impl_holder = new LDKFutureCallbackHolder();
55 impl_holder.held = new FutureCallback(new bindings.LDKFutureCallback() {
56 @Override public void call() {
58 Reference.reachabilityFence(arg);
61 return impl_holder.held;
64 * The method which is called.
67 bindings.FutureCallback_call(this.ptr);
68 Reference.reachabilityFence(this);