temporalio / sdk-java

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

Support a promise-based await #1937

Open ghaskins opened 7 months ago

ghaskins commented 7 months ago

An SDK function that works similarly to await but is based on promises rather than blocking could be useful to expand developer options for coordinating mixed event classes. For instance, coordinating an .all() on an invoked activity and receiving a signal.

This interface could be designed in several different ways. As an example:

Promise until(java.time.Duration timeout, java.util.function.Supplier<java.lang.Boolean> predicate)

This function would take a timeout and predicate, and return a promise. Temporal will evaluate the predicate on each state transition (similar to .await), and will resolve the promise with "true" if the predicate returns true. and "false" if the timeout expires.

ghaskins commented 7 months ago

Slack reference: https://temporalio.slack.com/archives/CTT84KXK9/p1700311804161219

mfateev commented 7 months ago

To be consistent with existing APIs, my proposal is as follows:

class Async {
...
     static Promise<Boolean> await(Duration timeout, Supplier<Boolean> unblockCondition);
}