Resonate is in the Design Phase
Our code base is constantly evolving as we are exploring Resonate's programming model. If you are passionate about a dead simple developer experience, join us on this journey of discovery and share your thoughts.
An SDK for writing simple and elegant durable async await applications.
Resonate offers a programming model that allows you to build distributed applications using an intuitive paradigm you already know — async await.
Durable Async Await are Functions and Promises that maintain progress in durable storage.
Available now:
- durable async await
- volatile async await
- retries
- tracing
- logging
Coming soon:
- rate limiting
- metrics
Let us know features you would like Resonate to support.
npm install @resonatehq/sdk
import express from "express";
import { Resonate, Context } from "@resonatehq/sdk";
/* Your async code using Resonate's Context */
type User = {
id: number;
name: string;
};
type Song = {
id: number;
title: string;
};
// Purchase song event handler
async function purchase(ctx: Context, user: User, song: Song): Promise<{ charge: any; access: any }> {
const charge = await ctx.run(chargeCreditCard, user, song);
const access = await ctx.run(unlockUserAccess, user, song);
return { charge, access };
}
async function chargeCreditCard(ctx: Context, user: User, song: Song): Promise<any> {
console.log("Charging credit card...");
return { status: "charged" };
}
async function unlockUserAccess(ctx: Context, user: User, song: Song): Promise<any> {
console.log("Unlocking user access...");
return { status: "unlocked" };
}
/* Express Application w/ Resonate Event Handler */
// Create Resonate instance
const resonate = new Resonate();
// Register purchase handler
resonate.register("durablePurchase", purchase);
// Initialize Express app with purchase route
const app = express();
app.post("/purchase", async (req, res) => {
// Dummy user and song data
const user = { id: 1, name: "John" };
const song = { id: 1, title: "Song 1" };
// Create unique ID for purchase execution. This is used to track the execution.
// Typically, this would be an external ID from your incoming request.
const purchaseId = `purchase-${user.id}-${song.id}`
// Execute durable purchase
try {
const result = await resonate.run("durablePurchase", purchaseId, user, song);
res.send(result);
} catch (err) {
res.status(500).send("Unable to purchase song");
}
});
app.listen(3000, () => {
console.log("App listening on port 3000");
});
Once the server is running, invoke the purchase endpoint.
curl -X POST localhost:3000/purchase
See our docs for more detailed information.
npm install
npm run lint
npm test
See our contribution guidelines.
The Resonate TypeScript SDK is available under the Apache 2.0 License.