@resonatehq/cloudflare
v0.2.0
Published
Resonate FaaS handler for Cloudflare Workers (TypeScript)
Readme
@resonatehq/cloudflare
@resonatehq/cloudflare is the official binding to run Resonate durable execution workers on Cloudflare Workers. Write long-running, stateful applications on short-lived, stateless serverless infrastructure.
Installation
npm install @resonatehq/cloudflareHow it works
When a Durable Function suspends (e.g. on yield* context.rpc() or context.sleep()), the Cloudflare Worker terminates. When the Durable Promise completes, the Resonate Server resumes the function by invoking the Worker again — no long-running process required.
Usage
Register your functions and export the HTTP handler from your Worker entry point:
import { Resonate } from "@resonatehq/cloudflare";
import type { Context } from "@resonatehq/cloudflare";
const resonate = new Resonate();
resonate.register("countdown", function* countdown(ctx: Context, n: number): Generator {
if (n <= 0) {
console.log("done");
return;
}
console.log(n);
yield* ctx.sleep(1000);
yield* ctx.rpc(countdown, n - 1);
});
// Export as a Cloudflare Workers fetch handler
export default {
fetch: resonate.httpHandler(),
};Deploy this as a Cloudflare Worker. The Resonate Server will call your Worker to invoke and resume durable functions.
See the Cloudflare Workers documentation to learn how to develop and deploy Workers.
Examples
Documentation
Full documentation: docs.resonatehq.io
