Skip to content

notation-dev/yieldstar

Repository files navigation

yieldstar 🤘

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;
});

Passing Parameters to Workflows

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
  // ...
});

Examples

To install dependencies:

bun install

To run an example:

bun start

About

JavaScript-native distributed workflows that can be orchestrated by any backend

Resources

Stars

Watchers

Forks

Packages

No packages published