Effect Integration

Demonstrates how to integrate Effect with actors for functional, type-safe programming with powerful error handling and dependency injection.

Features

  • Effect-wrapped actions - Write actor actions using Effect generators for composable, type-safe logic
  • Actor context as Effect service - Access actor state, broadcast, and other context via Effect's dependency injection
  • Structured logging - Effect-based logging utilities integrated with actor logging

Implementation

This example provides Effect bindings for actors. The core implementation wraps the actor context in Effect services, allowing you to write actions using Effect's generator syntax.

Key files:

Example usage:

import { actor } from "rivetkit";
import { Action } from "@rivetkit/effect";

export const counter = actor({
  state: { count: 0 },
  actions: {
    increment: Action.effect(function* (c, x: number) {
      yield* Action.updateState(c, (s) => { s.count += x; });
      const s = yield* Action.state(c);
      yield* Action.broadcast(c, "newCount", s.count);
      return s.count;
    }),
  },
});

Resources