Long-running API call + Async activity completion using CompletableFuture = Good combination?

I have an API that takes 3-4s to complete. My plan is to invoke this API in an Activity and then wrap the API call in a CompletableFuture. When I start this Activity, I will invoke “doNotCompleteOnReturn()”. Subsequently, I plan to use “thenAccept” to inform Temporal Cluster when the API returns a response.

Is this a good use case for Async activity completion so that we don’t block Worker on a slow API and let the Worker move on with other tasks?

I ask because this seems to be a very obvious use case for Async activity completion. However, when I took the “Interacting with Workflows with Java” course, in the section “When to Use Asynchronous Completion”, it’s explicitly mentioned that Async completion is performed by the “External system”, not by a CompletableFuture inside my Activity implementation.

Hence, I’m wondering if I have some flaws in my understanding of Async activity completion.

1 Like