Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Examples

This section provides practical examples demonstrating various features and patterns of the rsActor framework.

Available Examples

Core Patterns

Advanced Patterns

  • Kill Demo — Graceful stop vs immediate kill, ActorResult inspection
  • Ask Join — ask_join pattern with JoinHandle
  • Handler Demo — Handler traits for type-erased heterogeneous collections
  • Weak References — ActorWeak for breaking circular references
  • Metrics — Per-actor performance metrics
  • Tracing — Structured tracing and observability

Classic Problems

Running Examples

All examples are in the examples/ directory:

# Core examples
cargo run --example basic
cargo run --example actor_async_worker
cargo run --example actor_blocking_task

# Advanced examples
cargo run --example kill_demo
cargo run --example ask_join_demo
cargo run --example handler_demo
cargo run --example weak_reference_demo

# Feature-gated examples
cargo run --example metrics_demo --features metrics
cargo run --example tracing_demo --features tracing

Example Structure

Each example follows this pattern:

  1. Actor Definition: Define the actor struct and implement the Actor trait (or use #[derive(Actor)])
  2. Message Types: Define messages that the actor can handle
  3. Message Handlers: Use #[message_handlers] with #[handler] attributes
  4. Usage: Demonstrate spawning, messaging, and lifecycle management