Skip to content

Add CompletableFuture version of suspend, resume and cancel - #1651

Merged
fjtirado merged 1 commit into
open-workflow-specification:mainfrom
fjtirado:suspend_resume_completableFuture
Sep 2, 2026
Merged

Add CompletableFuture version of suspend, resume and cancel#1651
fjtirado merged 1 commit into
open-workflow-specification:mainfrom
fjtirado:suspend_resume_completableFuture

Conversation

@fjtirado

@fjtirado fjtirado commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Signed-off-by: Francisco Javier Tirado Sarti <ftirados@ibm.com>
Copilot AI lite review requested due to automatic review settings September 2, 2026 11:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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(), and cancelFuture() to WorkflowInstance as default methods.
  • Refactored WorkflowMutableInstance suspend/resume/cancel to share internal logic and added CompletableFuture<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.

@fjtirado
fjtirado merged commit d063e88 into open-workflow-specification:main Sep 2, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants