Add CompletableFuture version of suspend, resume and cancel - #1651
Conversation
Signed-off-by: Francisco Javier Tirado Sarti <ftirados@ibm.com>
There was a problem hiding this comment.
🟡 Changes recommended
The cancel-path now cancels dependent futures before emitting the workflow-cancelled lifecycle event, which can change observable event ordering and undermine the sequencing guarantees this PR aims to enable.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds CompletableFuture-based variants of workflow control operations (suspend/resume/cancel) so callers can compose/sequence these operations and (in some implementations) wait for lifecycle-event processing to complete.
Changes:
- Added
suspendFuture(),resumeFuture(), andcancelFuture()toWorkflowInstanceas default methods. - Refactored
WorkflowMutableInstancesuspend/resume/cancel to share internal logic and addedCompletableFuture<Boolean>variants that chain on lifecycle event publication.
File summaries
| File | Description |
|---|---|
| impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowMutableInstance.java | Adds future-returning control operations and refactors existing ones to share internal state-change logic and (for futures) await listener publication. |
| impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowInstance.java | Extends the public instance API with default future-returning suspend/resume/cancel methods for compatibility. |
Review details
Suppressed comments (1)
impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowMutableInstance.java:253
- New suspendFuture()/resumeFuture()/cancelFuture() behavior is not covered by tests. Given existing lifecycle-event tests cover suspend/resume/cancel, it would be valuable to add coverage that the returned CompletableFuture completes only after the corresponding lifecycle listeners/events have finished processing (the main motivation for introducing these APIs).
@Override
public CompletableFuture<Boolean> suspendFuture() {
return _suspend()
? publishEvent(
workflowContext,
l -> l.onWorkflowSuspended(new WorkflowSuspendedEvent(workflowContext)))
.thenApply(__ -> true)
: CompletableFuture.completedFuture(false);
}
- Files reviewed: 2/2 changed files
- Comments generated: 3
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
See quarkiverse/quarkus-flow#864 (comment)