1import { Resonate, Context } from "@resonatehq/sdk";
2
3// 1) Initialize Resonate executor
4const resonate = new Resonate();
5
6// 2) Register an async function as a durable async function
7resonate.register("purchase", purchase);
8
9async function purchase(ctx: Context, user: User, song: Song): Promise<Status> {
10 const charged = await ctx.run(charge, user, song);
11 const granted = await ctx.run(access, user, song);
12 return { charged, granted };
13}
14
15// 3) Setup logic for routing to durable async function
16app.post("/purchase", async (req: Request, res: Response) => {
17 const user = { id: req.body?.user ?? 1 };
18 const song = { id: req.body?.song ?? 1, price: 1.99 };
19
20 // 4) uniquely identify the execution
21 const id = `purchase-${user.id}-${song.id}`;
22 try {
23 res.send(await resonate.run("purchase", id, user, song));
24 } catch (err) {
25 res.status(500).send("Could not purchase song");
26 }
27});
Your App, Your Way
By extending instead of replacing async await, we have created an incremental transition from the world of concurrent programming into the world of distributed programming
Get retries, rate limiting, timeouts, cancelation, metrics, and tracing. No infrastructure required.
Run functions for minutes, hours, days, weeks, month, or years, regardless of hardware or software failures.
Run on prem, on the edge, in the cloud, or go serverless.