Back to Rivet

Hello World (Effect)

examples/hello-world-effect/README.md

2.3.22.0 KB
Original Source

Hello World (Effect)

Minimal counter actor built with the Effect SDK for Rivet Actors.

Getting Started

sh
git clone https://github.com/rivet-dev/rivet.git
cd rivet/examples/hello-world-effect
npm install
npm run dev

In a separate terminal, run the client against the server:

sh
npm run client

Features

  • Effect-native actors: Define an actor with Actor.make and implement it with toLayer, returning action handlers from an Effect wake scope
  • Typed action protocols: Increment and GetCount are standalone Action.make values with Schema payloads and successes validated end to end
  • Typed errors across the wire: Increment declares a NegativeAmountError that arrives on the caller as a real tagged instance, caught with Effect.catchTag
  • Persistent state: The counter value lives in persisted actor state, accessed through a SubscriptionRef-like State API
  • Events: Each increment broadcasts the new count to every connected client

Implementation

The actor is split into a public contract and a server-only implementation:

Resources

Read more about actions, state, events, and the Effect quickstart.

License

MIT