EffectTalk

Layer.scoped for managed resources

Use Layer.scoped when a service needs acquire/release logic (e.g. database connections). The resource is released when the scope ends.

This ensures cleanup runs even if the program fails.

  • Use scoped in service definition for resources that need cleanup
  • Use Effect.addFinalizer for release logic
  • Wrap the program in Effect.scoped when using scoped layers
Loading code editor...