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 struct which can be used to select across many [`Future`]s at once without relying on a full
15 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
16 public class Sleeper extends CommonBase {
17 Sleeper(Object _dummy, long ptr) { super(ptr); }
18 @Override @SuppressWarnings("deprecation")
19 protected void finalize() throws Throwable {
21 if (ptr != 0) { bindings.Sleeper_free(ptr); }
25 * Constructs a new sleeper from one future, allowing blocking on it.
27 public static Sleeper from_single_future(org.ldk.structs.Future future) {
28 long ret = bindings.Sleeper_from_single_future(future == null ? 0 : future.ptr);
29 Reference.reachabilityFence(future);
30 if (ret >= 0 && ret <= 4096) { return null; }
31 org.ldk.structs.Sleeper ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Sleeper(null, ret); }
32 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
33 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(future); };
38 * Constructs a new sleeper from two futures, allowing blocking on both at once.
40 public static Sleeper from_two_futures(org.ldk.structs.Future fut_a, org.ldk.structs.Future fut_b) {
41 long ret = bindings.Sleeper_from_two_futures(fut_a == null ? 0 : fut_a.ptr, fut_b == null ? 0 : fut_b.ptr);
42 Reference.reachabilityFence(fut_a);
43 Reference.reachabilityFence(fut_b);
44 if (ret >= 0 && ret <= 4096) { return null; }
45 org.ldk.structs.Sleeper ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Sleeper(null, ret); }
46 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
47 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(fut_a); };
48 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(fut_b); };
53 * Constructs a new sleeper on many futures, allowing blocking on all at once.
55 public static Sleeper of(Future[] futures) {
56 long ret = bindings.Sleeper_new(futures != null ? Arrays.stream(futures).mapToLong(futures_conv_8 -> futures_conv_8 == null ? 0 : futures_conv_8.ptr).toArray() : null);
57 Reference.reachabilityFence(futures);
58 if (ret >= 0 && ret <= 4096) { return null; }
59 org.ldk.structs.Sleeper ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Sleeper(null, ret); }
60 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
61 for (Future futures_conv_8: futures) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(futures_conv_8); }; };
66 * Wait until one of the [`Future`]s registered with this [`Sleeper`] has completed.
68 public void wait_indefinite() {
69 bindings.Sleeper_wait(this.ptr);
70 Reference.reachabilityFence(this);
74 * Wait until one of the [`Future`]s registered with this [`Sleeper`] has completed or the
75 * given amount of time has elapsed. Returns true if a [`Future`] completed, false if the time
78 public boolean wait_timeout(long max_wait) {
79 boolean ret = bindings.Sleeper_wait_timeout(this.ptr, max_wait);
80 Reference.reachabilityFence(this);
81 Reference.reachabilityFence(max_wait);