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 on many futures, allowing blocking on all at once.
50 public static Sleeper of(Future[] futures) {
51 long ret = bindings.Sleeper_new(InternalUtils.encodeUint64Array(InternalUtils.mapArray(futures, futures_conv_8 => futures_conv_8.ptr)));
52 GC.KeepAlive(futures);
53 if (ret >= 0 && ret <= 4096) { return null; }
54 org.ldk.structs.Sleeper ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Sleeper(null, ret); }
55 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
56 foreach (Future futures_conv_8 in futures) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(futures_conv_8); };
57 // Due to rust's strict-ownership memory model, in some cases we need to "move"
58 // an object to pass exclusive ownership to the function being called.
59 // In most cases, we avoid ret_hu_conv being visible in GC'd languages by cloning the object
60 // at the FFI layer, creating a new object which Rust can claim ownership of
61 // However, in some cases (eg here), there is no way to clone an object, and thus
62 // we actually have to pass full ownership to Rust.
63 // Thus, after ret_hu_conv call, futures_conv_8 is reset to null and is now a dummy object.
64 futures_conv_8.ptr = 0;; };
69 * Wait until one of the [`Future`]s registered with this [`Sleeper`] has completed.
72 bindings.Sleeper_wait(this.ptr);
77 * Wait until one of the [`Future`]s registered with this [`Sleeper`] has completed or the
78 * given amount of time has elapsed. Returns true if a [`Future`] completed, false if the time
81 public bool wait_timeout(long max_wait) {
82 bool ret = bindings.Sleeper_wait_timeout(this.ptr, max_wait);
84 GC.KeepAlive(max_wait);