** Currently only works in chrome **
A fun demo showing how Resonate Workers can be hosted in the browser using the Resonate TypeScript SDK.
This demo implements a recursive factorial function that:
- Executes in the browser as a Resonate worker
- Can be triggered by creating promises via the Resonate CLI
Install the Resonate Server:
brew install resonatehq/tap/resonate
Start the Resonate Server without persistence and with CORS enabled:
resonate serve --aio-store-sqlite-path :memory: --api-http-cors-allow-origin "*" --aio-sender-plugin-poll-cors-allow-origin "*"
npm run dev
Create a durable promise representing the durable invocation of factorial(5)
resonate promises create factorial.5 \
--idempotency-key factorial.5 \
--timeout 1h \
--data '{"func":"factorial","args":[5]}' \
--tag resonate:invoke=poll://any@default
Fetch the result
resonate promises get factorial.5
You should see:
- Recursive calls displayed in the browser:
factorial(5) called
,factorial(4) called
, etc. - Final result: 120 (5! = 5×4×3×2×1)
npm run build
- Build the browser bundlenpm run dev
- Build and serve with auto-refreshnpm run serve
- Serve the built files
- Frontend: Browser worker polling for tasks via Server-Sent Events
- Backend: Resonate server managing distributed state and task routing
- Communication: HTTP API for task claiming, SSE for real-time updates