-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Async Activity support for Java async API #2049
Comments
Given how the Java SDK uses stubs for type safety and how the Java SDK cannot use Java's native concurrent primitives I don't think this proposal is feasible as describe.
The Java SDK cannot support Java's native concurrent primitives like If an activity is invoked in a synchronous or asynchronous manner is determined by the caller (workflow), not the activity so a
So if this is a concern the Java SDK support async activities without blocking a thread using Line 39 in ed211fa
We also plan to support virtual threads in the near future that would also make this easier. |
Hello Quinn,
Though what you said sounds good sense to me, there's still something I don't fully understand yet.
IIUC (proposition is based on my understanding), the main issue is from the workflow side as composing
Thanks for this example, and I pick some ideas from it as well to adapt my proposition. The issue with the current mechanism is that it's somehow intrusive to user code, and activity developers have to think about doing it. In fact this mechanism is documented, I read it quickly when I saw it for the first time, and I forgot about it quickly because I did not fully grasp the reason why it is proposed. |
Is your feature request related to a problem? Please describe.
In activity implementations, we often deal with Java async APIs (for example, the new
java.net.http
api in Java 11). And such APIs usually return aFuture
orCompletionStage
(less often), or even betterCompletableFuture
. Currently Activity invocation is not aware of these types and does not wait until the completion of them, which means we have to block and wait in client activity implementations (aka.ActivityMethod
).This is not very convenient:
Future#get
in anActivityMethod
, and this will cause a bug such that temporal considers an activity as done while it is not. (This is more likely to happen if the activity ends up in calling some service that returns aCompletableFuture<Void>
as we usually don't expect to deal with the result specifically.)CompletionStage
's compose APIs to combine activities in order (we have to use Temporal'sAsync
static APIs for the purpose)Describe the solution you'd like
To keep consistency with current behaviour and also make it explicit about (enabling) support of the java
CompletableFuture
, I propose to provideAsyncActivityMethod
annotation to be used on methods that are returning ajava.util.concurrent.CompletableFuture
and we expect the result to be completed before activity is done. More precisely:AsyncActivityMethod
should returnjava.util.concurrent.CompletableFuture
as an requirement.java.util.concurrent.CompletableFuture
but annotated withActivityMethod
will continue to behave current way which is launching some async task and complete the activity without waiting for it (activity is just to launch something and does not care about the result).AsyncActivityMethod
activity is considered done only when theCompletableFuture
is completed.Describe alternatives you've considered
I am open to other propositions.
Additional context
The text was updated successfully, but these errors were encountered: