# Future-Completable RPC Call

**URL:** <https://forum.inductiveautomation.com/t/future-completable-rpc-call/64833>\
**Category:** Module Development\
**Created:** [October 5, 2022, 5:27am UTC](https://forum.inductiveautomation.com/t/future-completable-rpc-call/64833 "2022-10-05T05:27:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bmusson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmusson/32/87530_2.png) [@bmusson](https://forum.inductiveautomation.com/u/bmusson)\
**Post date:** [October 5, 2022, 5:27am UTC](https://forum.inductiveautomation.com/t/future-completable-rpc-call/64833/1 "2022-10-05T05:27:30Z")

</div>

I have an RPC method that can take a while to complete. I have no issues completing the task asynchronously purely on the Gateway; but when calling the method from an RPC, I can't serialize a `CompletableFuture` so I'm stuck blocking the client.

What are my options for giving the client/designer a _CompletableFuture_-type-thing that eventually gets completed by the Gateway?

I've found the `ClientProgressManager` and `GatewayProgressManager`, but I'm having a hard time determining what's required/optional (I'm also not interested in displaying a progress bar in the client). My task already manages its own threading and lifecycle, in case that matters.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 5, 2022, 11:56am UTC](https://forum.inductiveautomation.com/t/future-completable-rpc-call/64833/2 "2022-10-05T11:56:53Z")

</div>

You need to use messaging. Return a handle from the initial call. Maintain a map in the client of incomplete Futures by handle. The gateway's implementation then sends a message to that client with handle and result. Your client/designer message handler looks up and completes the future.

Your gateway RPC hook method needs to create and cache implementations that retain the client session supplied, so that your implementation has the session needed to send back to the specific client.

---

<div class="post-metadata">

**Author:** ![bmusson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmusson/32/87530_2.png) [@bmusson](https://forum.inductiveautomation.com/u/bmusson)\
**Post date:** [October 6, 2022, 7:18pm UTC](https://forum.inductiveautomation.com/t/future-completable-rpc-call/64833/3 "2022-10-06T19:18:01Z")

</div>

Thanks Phil.

Some notes for my future self and others:

1. To push to a designer/client from the gateway, add a notification to the session received from the RPC call using:

```auto
session.addNotification(...)

```

1. To listen for this notification in the designer/client, you first need a GatewayConnection object. _Don't make a new connection_, get one from the _GatewayConnectionManager_.

```auto
new DesignerGatewayConnection(context.getLaunchContext()) # incorrect
GatewayConnectionManager.getInstance() # correct

```

1. In the designer/client, add a push notification listener to the _GatewayConnection_ to handle the notification:

```auto
GatewayConnection connection = GatewayConnectionManager.getInstance();
connection.addPushNotificationListener(...);
connection.removePushNotificationListener(...);

```
