X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=c_sharp%2Fsrc%2Forg%2Fldk%2Fstructs%2FFuture.cs;fp=c_sharp%2Fsrc%2Forg%2Fldk%2Fstructs%2FFuture.cs;h=b48dbf6f75137259e85a2984764e04f49c7cb50e;hb=c6777737ea14e7814b0fa7d6fe16536f31d4a82b;hp=5fa004adb38c7a3715cb2ca7cfabda5b87bc5761;hpb=ee72c84d4bf9e2404e02fe20155efb502ceaee1b;p=ldk-java diff --git a/c_sharp/src/org/ldk/structs/Future.cs b/c_sharp/src/org/ldk/structs/Future.cs index 5fa004ad..b48dbf6f 100644 --- a/c_sharp/src/org/ldk/structs/Future.cs +++ b/c_sharp/src/org/ldk/structs/Future.cs @@ -8,6 +8,8 @@ namespace org { namespace ldk { namespace structs { /** * A simple future which can complete once, and calls some callback(s) when it does so. + * + * Clones can be made and all futures cloned from the same source will complete at the same time. */ public class Future : CommonBase { internal Future(object _dummy, long ptr) : base(ptr) { } @@ -15,16 +17,56 @@ public class Future : CommonBase { if (ptr != 0) { bindings.Future_free(ptr); } } + internal long clone_ptr() { + long ret = bindings.Future_clone_ptr(this.ptr); + GC.KeepAlive(this); + return ret; + } + + /** + * Creates a copy of the Future + */ + public Future clone() { + long ret = bindings.Future_clone(this.ptr); + GC.KeepAlive(this); + if (ret >= 0 && ret <= 4096) { return null; } + org.ldk.structs.Future ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Future(null, ret); } + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); }; + return ret_hu_conv; + } + /** * Registers a callback to be called upon completion of this future. If the future has already * completed, the callback will be called immediately. */ public void register_callback_fn(org.ldk.structs.FutureCallback callback) { - bindings.Future_register_callback_fn(this.ptr, callback == null ? 0 : callback.ptr); + bindings.Future_register_callback_fn(this.ptr, callback.ptr); GC.KeepAlive(this); GC.KeepAlive(callback); if (this != null) { this.ptrs_to.AddLast(callback); }; } + /** + * Waits until this [`Future`] completes. + */ + public void wait() { + bindings.Future_wait(this.ptr); + GC.KeepAlive(this); + if (this != null) { this.ptrs_to.AddLast(this); }; + } + + /** + * Waits until this [`Future`] completes or the given amount of time has elapsed. + * + * Returns true if the [`Future`] completed, false if the time elapsed. + */ + public bool wait_timeout(long max_wait) { + bool ret = bindings.Future_wait_timeout(this.ptr, max_wait); + GC.KeepAlive(this); + GC.KeepAlive(max_wait); + if (this != null) { this.ptrs_to.AddLast(this); }; + return ret; + } + } } } }