Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an API for composing workflows #27

Open
benjavicente opened this issue Jan 7, 2025 · 1 comment
Open

Add an API for composing workflows #27

benjavicente opened this issue Jan 7, 2025 · 1 comment

Comments

@benjavicente
Copy link

benjavicente commented Jan 7, 2025

export const parentWorkflow = workflow.define({
  handler: async (step) => {
    await step.runWorkflow(internal.example.childWorkflow, childWorkflowArgs)
  }
})

If the parent workflow is canceled, every child workflow should be canceled.

@benjavicente
Copy link
Author

Alternative (and wilder) idea: have a promise-like-API

// The run is disconected from the parent workflow
const childWorkflowReference = await step.workflow.start(internal.example.childWorkflow, childWorkflowArgs)

const value = await step.workflow.wait(childWorkflowReference) // await
await step.workflow.allSettled( ... ) // returns the statues and values 

await step.workflow.all( ... )  // if any workflow faill, calcel the parent and every child that is running
await step.workflow.any( ... ) // get the first that works, cancel every other that is still running
await step.workflow.race( ... )  // get the first workflow that ended, cancel every other that is still running
// Since the last 3 don't wait for every workflow to stop, there could be a second argument like `{ cancelOthers: true }`

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

No branches or pull requests

1 participant