lifecycle Examples
This folder contains runnable examples demonstrating various features of the lifecycle library.
Basic Patterns (CLI & Automation)
These examples demonstrate the core "Death Management" features (v1.0-v1.4). Ideal for CLIs, Scripts, and simple Tools.
- basic: The "Hello World" of
lifecycle. Shows Run, Go, and Job.
- context: Manual setup via
lifecycle.Context() for gradual migration.
- hooks: How to register and execute synchronous/asynchronous cleanup hooks.
- interactive_dx: Safe reading from Stdin (Windows
CONIN$ support) that respects context cancellation.
Advanced Patterns (Control Plane v1.5+)
These examples demonstrate "Life Management" capabilities (v1.5+). Ideal for Services, Daemons, and Agents.
- suspend: The full Control Plane experience. Shows Supervisors, Suspend/Resume events, and Durable Execution.
- supervisor: Managing a tree of child processes/workers with restart policies.
- repl: Building an interactive REPL that handles signals and custom commands.
Recipes
Specific solutions to common problems.
- zombie: Demonstrating Process Hygiene (Job Objects / PDeathSig) to ensure child processes die with the parent.
- reliability: Using
lifecycle.Do for safe execution.
- observability: Visualizing the system state with Mermaid.