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;
12 * A simple future which can complete once, and calls some callback(s) when it does so.
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class Future extends CommonBase {
16 Future(Object _dummy, long ptr) { super(ptr); }
17 @Override @SuppressWarnings("deprecation")
18 protected void finalize() throws Throwable {
20 if (ptr != 0) { bindings.Future_free(ptr); }
24 * Registers a callback to be called upon completion of this future. If the future has already
25 * completed, the callback will be called immediately.
27 public void register_callback_fn(org.ldk.structs.FutureCallback callback) {
28 bindings.Future_register_callback_fn(this.ptr, callback.ptr);
29 Reference.reachabilityFence(this);
30 Reference.reachabilityFence(callback);
31 if (this != null) { this.ptrs_to.add(callback); };
35 * Waits until this [`Future`] completes.
37 public void wait_indefinite() {
38 bindings.Future_wait(this.ptr);
39 Reference.reachabilityFence(this);
43 * Waits until this [`Future`] completes or the given amount of time has elapsed.
45 * Returns true if the [`Future`] completed, false if the time elapsed.
47 public boolean wait_timeout(long max_wait) {
48 boolean ret = bindings.Future_wait_timeout(this.ptr, max_wait);
49 Reference.reachabilityFence(this);
50 Reference.reachabilityFence(max_wait);