temporalio / sdk-java

Temporal Java SDK
https://temporal.io
Apache License 2.0
217 stars 146 forks source link

Support different coroutine models in workflows and activities #1845

Open cretz opened 1 year ago

cretz commented 1 year ago

Describe the solution you'd like

Need to several things:

This is kinda a big project, so some discussion should happen first. The above is just speculation about what to do.

rocketraman commented 11 months ago

As a Kotlin user who is getting started with Temporal, I would love to see this. Calls like Workflow.sleep() block a platform thread, which isn't scalable and is annoying in principle even where its not an actual scalability issue :-)

Kotlin coroutines, and more recently with the release of JDK 21 and Java virtual threads, are a perfect solution to this problem as they take up almost no resources while blocked on workflow sleep or activity calls.

I know nothing about the Java SDK internals, but looking at it from the outside in, the most basic abstraction of an async call is a callback. These are easy to bridge to suspending calls in Kotlin, and presumably to Java fibers. So if the SDK exposed async versions of its API that took a callback to resume the workflow execution, this would be easy to turn back into regular synchronous but non-blocking code via coroutines, and presumably fibers.

Issues which are probably duplicates or at least related to this one, based on the search I just did: