Skip to content

resonatehq/resonate-faas-cloudflare-ts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@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/cloudflare

How 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.

Resonate on Serverless

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

About

TypeScript FaaS adapter for Resonate on Cloudflare Workers

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •