JavaScript-native distributed workflows that can be orchestrated by any backend.
import { workflow, RetryableError } from "yieldstar";
const myWorkflow = workflow(async function* (step, event, logger) {
const { params } = event; // Access workflow parameters
let num = yield* step.run(() => {
return fetch("https://randomnumber.com")
.then((res) => res.json())
.catch((err) => {
throw new RetryableError(err, { maxAttempts: 5, retryInterval: 1000 });
});
});
yield* step.delay(5000);
num = yield* step.run(async () => {
num * (await fetch("https://randomnumber.com").then((res) => res.json()));
});
return num;
});
You can pass parameters to workflows when triggering them:
const result = await sdk.triggerAndWait({
workflowId: "myWorkflow",
params: {
userId: "123",
action: "create",
},
});
Inside the workflow, you can access the parameters through the event
object:
const myWorkflow = workflow(async function* (step, event, logger) {
const { params } = event;
logger.info(`Processing action ${params.action} for user ${params.userId}`);
// Use the parameters in your workflow logic
// ...
});
To install dependencies:
bun install
To run an example:
bun start