Cookbook

Short recipes for jobs that come up in real services, daemons and CLIs. Each recipe is backed by a runnable example in the repository that finishes in well under a second and asserts its own result.

RecipeCratesExample
Retry with virtual timeid_effect, id_effect_resilience010_retry_with_breaker, crates/id_effect/tests/schedule.rs
Bounded subprocess poolid_effect, id_effect_platform152_cookbook_bounded_command_pool
A CLI with run_mainid_effect_cli, id_effect_config153_cookbook_cli_edge
Supervised daemon skeletonid_effect_process154_cookbook_supervised_daemon
Streaming ETL with bounded memoryid_effect151_cookbook_streaming_etl

Run them from the repository root:

cargo run -p id_effect_resilience --example 010_retry_with_breaker
cargo run -p id_effect_platform --example 152_cookbook_bounded_command_pool
cargo run -p cli_minimal --example 153_cookbook_cli_edge -- --name Ada
cargo run -p id_effect_process --example 154_cookbook_supervised_daemon
cargo run -p id_effect --example 151_cookbook_streaming_etl

All five follow one pattern:

  1. Write the program as an Effect<A, E, R> whose R lists the capabilities it needs (caps!(A, B) or an explicit HCons<A, HCons<B, HNil>>).
  2. Provide the real capabilities once, at the edge (main): .provide_env(..), .provide_layer(..) or run_main(program, env, config).
  3. In tests, provide fakes instead (a MapConfigProvider, a recording console, an instrumented source) and run time-based code on a TestExecutor, whose virtual clock moves only when the test advances it.