Examples

With Retries

Automatic retry behavior for flaky operations.

signals/flaky-task.ts

import { signal, z } from "station-signal"; export const flakyTask = signal("flakyTask")  .input(z.object({ message: z.string() }))  .timeout(3_000)  .retries(3)  .run(async (input) => {    const shouldFail = Math.random() < 0.6;     if (shouldFail) {      console.log(`[flakyTask] "${input.message}" — failed! (will retry)`);      throw new Error("Random failure");    }     console.log(`[flakyTask] "${input.message}" — success!`);  });

.retries(3) means 4 total attempts (1 initial + 3 retries). .timeout(3_000) kills the handler after 3 seconds. With a 60% failure rate, the signal almost always succeeds within 4 attempts.

Run it: pnpm --filter example-with-retries start


← All examples