X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FFuture.java;h=74c5a62a50adb33585bed1aba36530b262219602;hb=4a36fa97d4eee96099c4a176ea845c52db27e64c;hp=4a9d0c5e24dc9b049dbfd31048fcc9af66821975;hpb=46763b974f120d1795fca6c1e757578784f3305a;p=ldk-java diff --git a/src/main/java/org/ldk/structs/Future.java b/src/main/java/org/ldk/structs/Future.java index 4a9d0c5e..74c5a62a 100644 --- a/src/main/java/org/ldk/structs/Future.java +++ b/src/main/java/org/ldk/structs/Future.java @@ -10,6 +10,8 @@ import javax.annotation.Nullable; /** * 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. */ @SuppressWarnings("unchecked") // We correctly assign various generic arrays public class Future extends CommonBase { @@ -20,6 +22,24 @@ public class Future extends CommonBase { if (ptr != 0) { bindings.Future_free(ptr); } } + long clone_ptr() { + long ret = bindings.Future_clone_ptr(this.ptr); + Reference.reachabilityFence(this); + return ret; + } + + /** + * Creates a copy of the Future + */ + public Future clone() { + long ret = bindings.Future_clone(this.ptr); + Reference.reachabilityFence(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.add(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. @@ -31,4 +51,26 @@ public class Future extends CommonBase { if (this != null) { this.ptrs_to.add(callback); }; } + /** + * Waits until this [`Future`] completes. + */ + public void wait_indefinite() { + bindings.Future_wait(this.ptr); + Reference.reachabilityFence(this); + if (this != null) { this.ptrs_to.add(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 boolean wait_timeout(long max_wait) { + boolean ret = bindings.Future_wait_timeout(this.ptr, max_wait); + Reference.reachabilityFence(this); + Reference.reachabilityFence(max_wait); + if (this != null) { this.ptrs_to.add(this); }; + return ret; + } + }