Projects

Flow Like Water

A TypeScript library for multi-step tasks, with retries, conditions, and state you can save.

Workflow 7 tasks
Complete
Init branches into fetch and auth, then cache and validate, and rejoins at transform before finishing. Select a task for details.initfetchauthcachevalidatetransformdone
6 completed, 1 skipped10.2s
Simulated run · 9/9

A scripted example. Select a task to see its state, or drag the timeline to move through the run.

Working with tasks

Retries

Give each task its own retry limit and delay. A delay function can add exponential backoff.

new Task({
  id: 'deploy-pod',
  execute: () => deployPod(),
  retries: 5,
  waitTime: (attempt) =>
    Math.min(1000 * 2 ** attempt,
      30000),
});

Conditions

Skip work that's already done. Return a task ID from execute to choose the next step.

new Task({
  id: 'create-namespace',
  checkCondition: async () =>
    !(await namespaceExists()),
  execute: async () => {
    await createNamespace();
    return 'deploy-app';
  },
});

Saved state

Serialize the run, store it, and use that record to decide which task to resume later.

const state = flow
  .getSerializedState();

await save(state);

// Later, resume an unfinished task.
await flow.runTask(taskId);

Examples are abbreviated; service and storage helpers are omitted. The repository has the full API.