Skip to content

Your first durable function.

Quickstart / Local development

Install the server and an SDK, run a countdown, then restart the worker to see the countdown resume.

Terminal window
brew install resonatehq/tap/resonate

Choose a language here. The function, worker command, and result below will use the same SDK.

Requires Node.js 22 or later.

Terminal window
npm install @resonatehq/sdk

A countdown loop that survives restarts — minutes, hours, or days.

countdown.ts
import { Resonate, type Context } from "@resonatehq/sdk";
function* countdown(context: Context, count: number, delay: number) {
for (let i = count; i > 0; i--) {
// Run a function, persist its result
yield* context.run((context: Context) => console.log(`Countdown: ${i}`));
// Sleep
yield* context.sleep(delay * 1000);
}
console.log("Done!");
}
// Instantiate Resonate
const resonate = new Resonate({ url: "http://localhost:8001" });
// Register the function
resonate.register(countdown);

Working example

Terminal window
resonate dev
Terminal window
npx ts-node countdown.ts

Run the function with execution ID countdown.1:

Terminal window
resonate invoke countdown.1 --func countdown --arg 5 --arg 60
Terminal window
npx ts-node countdown.ts
Countdown: 5
Countdown: 4
Countdown: 3
Countdown: 2
Countdown: 1
Done!

Inspect the execution with resonate tree — it renders the call graph as durable promises.

Terminal window
resonate tree countdown.1