Skip to content

Add .rollback() api for workflow step promises#6330

Open
vaishnav-mk wants to merge 2 commits intocloudflare:mainfrom
vaishnav-mk:vaish/feat/saga-rollback-api
Open

Add .rollback() api for workflow step promises#6330
vaishnav-mk wants to merge 2 commits intocloudflare:mainfrom
vaishnav-mk:vaish/feat/saga-rollback-api

Conversation

@vaishnav-mk
Copy link
Contributor

adds steppromise wrapper with .rollback() api for workflow saga rollbacks. step.do() and step.waitforevent() now return steppromise which lets users register a compensation function before the step rpc fires.

  • sleep/sleepuntil are unchanged.
  • includes type declarations and tests.

@vaishnav-mk vaishnav-mk requested review from a team as code owners March 16, 2026 10:01
// https://opensource.org/licenses/Apache-2.0

import { RpcTarget } from 'cloudflare:workers';
import * as assert from 'node:assert';
Copy link
Member

Choose a reason for hiding this comment

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

not needed

Suggested change
import * as assert from 'node:assert';
import assert from 'node:assert';

class MockStep extends RpcTarget {
constructor() {
super();
this.calls = [];
Copy link
Member

Choose a reason for hiding this comment

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

this can be moved to outside of the constructor and we can remove the constructor statement

Comment on lines +71 to +72
configOrFn !== null &&
configOrFn !== undefined &&
Copy link
Member

Choose a reason for hiding this comment

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

This does the same exact thing

Suggested change
configOrFn !== null &&
configOrFn !== undefined &&
configOrFn != null &&

if (!this.#promise) {
this.#launched = true;
// #execute is non-null here because #promise is only set in this block.
this.#promise = this.#execute!(this.#rollbackFn, this.#rollbackConfig);
Copy link
Member

Choose a reason for hiding this comment

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

Can we eliminate the non-null ! somehow?

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