[Java] Update auto-generated bindings to LDK 0.0.123
[ldk-java] / src / main / java / org / ldk / structs / Sleeper.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10
11 /**
12  * A struct which can be used to select across many [`Future`]s at once without relying on a full
13  * async context.
14  */
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 {
20                 super.finalize();
21                 if (ptr != 0) { bindings.Sleeper_free(ptr); }
22         }
23
24         /**
25          * Constructs a new sleeper from one future, allowing blocking on it.
26          */
27         public static Sleeper from_single_future(org.ldk.structs.Future future) {
28                 long ret = bindings.Sleeper_from_single_future(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); };
34                 return ret_hu_conv;
35         }
36
37         /**
38          * Constructs a new sleeper from two futures, allowing blocking on both at once.
39          */
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.ptr, 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); };
49                 return ret_hu_conv;
50         }
51
52         /**
53          * Constructs a new sleeper on many futures, allowing blocking on all at once.
54          */
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.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); };
62                 // Due to rust's strict-ownership memory model, in some cases we need to "move"
63                 // an object to pass exclusive ownership to the function being called.
64                 // In most cases, we avoid ret_hu_conv being visible in GC'd languages by cloning the object
65                 // at the FFI layer, creating a new object which Rust can claim ownership of
66                 // However, in some cases (eg here), there is no way to clone an object, and thus
67                 // we actually have to pass full ownership to Rust.
68                 // Thus, after ret_hu_conv call, futures_conv_8 is reset to null and is now a dummy object.
69                 futures_conv_8.ptr = 0;; };
70                 return ret_hu_conv;
71         }
72
73         /**
74          * Wait until one of the [`Future`]s registered with this [`Sleeper`] has completed.
75          */
76         public void wait_indefinite() {
77                 bindings.Sleeper_wait(this.ptr);
78                 Reference.reachabilityFence(this);
79         }
80
81         /**
82          * Wait until one of the [`Future`]s registered with this [`Sleeper`] has completed or the
83          * given amount of time has elapsed. Returns true if a [`Future`] completed, false if the time
84          * elapsed.
85          */
86         public boolean wait_timeout(long max_wait) {
87                 boolean ret = bindings.Sleeper_wait_timeout(this.ptr, max_wait);
88                 Reference.reachabilityFence(this);
89                 Reference.reachabilityFence(max_wait);
90                 return ret;
91         }
92
93 }