73c4d7b0564173a585bddc8fc9727ce800c83a18
[ldk-java] / c_sharp / src / org / ldk / structs / FutureCallback.cs
1 using org.ldk.impl;
2 using org.ldk.enums;
3 using org.ldk.util;
4 using System;
5
6 namespace org { namespace ldk { namespace structs {
7
8 /**
9  * A callback which is called when a [`Future`] completes.
10  * 
11  * Note that this MUST NOT call back into LDK directly, it must instead schedule actions to be
12  * taken later. Rust users should use the [`std::future::Future`] implementation for [`Future`]
13  * instead.
14  * 
15  * Note that the [`std::future::Future`] implementation may only work for runtimes which schedule
16  * futures when they receive a wake, rather than immediately executing them.
17  */
18 public class FutureCallback : CommonBase {
19         internal readonly bindings.LDKFutureCallback bindings_instance;
20         internal FutureCallback(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
21         private FutureCallback(bindings.LDKFutureCallback arg) : base(bindings.LDKFutureCallback_new(arg)) {
22                 this.ptrs_to.AddLast(arg);
23                 this.bindings_instance = arg;
24         }
25         ~FutureCallback() {
26                 if (ptr != 0) { bindings.FutureCallback_free(ptr); }
27         }
28
29         public interface FutureCallbackInterface {
30                 /**
31                  * The method which is called.
32                  */
33                 void call();
34         }
35         private class LDKFutureCallbackHolder { internal FutureCallback held; }
36         private class LDKFutureCallbackImpl : bindings.LDKFutureCallback {
37                 internal LDKFutureCallbackImpl(FutureCallbackInterface arg, LDKFutureCallbackHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
38                 private FutureCallbackInterface arg;
39                 private LDKFutureCallbackHolder impl_holder;
40                 public void call() {
41                         arg.call();
42                                 GC.KeepAlive(arg);
43                 }
44         }
45         public static FutureCallback new_impl(FutureCallbackInterface arg) {
46                 LDKFutureCallbackHolder impl_holder = new LDKFutureCallbackHolder();
47                 impl_holder.held = new FutureCallback(new LDKFutureCallbackImpl(arg, impl_holder));
48                 return impl_holder.held;
49         }
50         /**
51          * The method which is called.
52          */
53         public void call() {
54                 bindings.FutureCallback_call(this.ptr);
55                 GC.KeepAlive(this);
56         }
57
58 }
59 } } }