6 namespace org { namespace ldk { namespace structs {
10 * A struct which can be used to select across many [`Future`]s at once without relying on a full
13 public class Sleeper : CommonBase {
14 internal Sleeper(object _dummy, long ptr) : base(ptr) { }
16 if (ptr != 0) { bindings.Sleeper_free(ptr); }
20 * Constructs a new sleeper from one future, allowing blocking on it.
22 public static Sleeper from_single_future(org.ldk.structs.Future future) {
23 long ret = bindings.Sleeper_from_single_future(future.ptr);
25 if (ret >= 0 && ret <= 4096) { return null; }
26 org.ldk.structs.Sleeper ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Sleeper(null, ret); }
27 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
28 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(future); };
33 * Constructs a new sleeper from two futures, allowing blocking on both at once.
35 public static Sleeper from_two_futures(org.ldk.structs.Future fut_a, org.ldk.structs.Future fut_b) {
36 long ret = bindings.Sleeper_from_two_futures(fut_a.ptr, fut_b.ptr);
39 if (ret >= 0 && ret <= 4096) { return null; }
40 org.ldk.structs.Sleeper ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Sleeper(null, ret); }
41 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
42 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(fut_a); };
43 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(fut_b); };
48 * Constructs a new sleeper from three futures, allowing blocking on all three at once.
50 public static Sleeper from_three_futures(org.ldk.structs.Future fut_a, org.ldk.structs.Future fut_b, org.ldk.structs.Future fut_c) {
51 long ret = bindings.Sleeper_from_three_futures(fut_a.ptr, fut_b.ptr, fut_c.ptr);
55 if (ret >= 0 && ret <= 4096) { return null; }
56 org.ldk.structs.Sleeper ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Sleeper(null, ret); }
57 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
58 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(fut_a); };
59 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(fut_b); };
60 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(fut_c); };
65 * Constructs a new sleeper on many futures, allowing blocking on all at once.
67 public static Sleeper of(Future[] futures) {
68 long ret = bindings.Sleeper_new(InternalUtils.encodeUint64Array(InternalUtils.mapArray(futures, futures_conv_8 => futures_conv_8.ptr)));
69 GC.KeepAlive(futures);
70 if (ret >= 0 && ret <= 4096) { return null; }
71 org.ldk.structs.Sleeper ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Sleeper(null, ret); }
72 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
73 foreach (Future futures_conv_8 in futures) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(futures_conv_8); };
74 // Due to rust's strict-ownership memory model, in some cases we need to "move"
75 // an object to pass exclusive ownership to the function being called.
76 // In most cases, we avoid ret_hu_conv being visible in GC'd languages by cloning the object
77 // at the FFI layer, creating a new object which Rust can claim ownership of
78 // However, in some cases (eg here), there is no way to clone an object, and thus
79 // we actually have to pass full ownership to Rust.
80 // Thus, after ret_hu_conv call, futures_conv_8 is reset to null and is now a dummy object.
81 futures_conv_8.ptr = 0;; };
86 * Wait until one of the [`Future`]s registered with this [`Sleeper`] has completed.
89 bindings.Sleeper_wait(this.ptr);
94 * Wait until one of the [`Future`]s registered with this [`Sleeper`] has completed or the
95 * given amount of time has elapsed. Returns true if a [`Future`] completed, false if the time
98 public bool wait_timeout(long max_wait) {
99 bool ret = bindings.Sleeper_wait_timeout(this.ptr, max_wait);
101 GC.KeepAlive(max_wait);