- Home
- Skills
- Andrueandersoncs
- Claude Skill Effect Ts
- Resource Management
resource-management_skill
- TypeScript
5
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill andrueandersoncs/claude-skill-effect-ts --skill resource-management- SKILL.md5.7 KB
Overview
This skill explains how to manage resources safely using Effect so cleanup is guaranteed even on errors or interruptions. It covers scopes, acquire/release patterns, finalizers, scoped effects, and common resource examples like files, DB connections, and locks. The focus is practical: how to acquire, use, and reliably release resources in real programs.
How this skill works
Effect tracks resources inside a Scope and attaches finalizers that run when the scope closes. acquireRelease/acquireUseRelease pair acquisition with deterministic cleanup. Effect.scoped runs a scoped effect and automatically closes the scope, running all finalizers in reverse acquisition order. Tools like addFinalizer, ensuring, and onExit provide flexible hooks for cleanup and exit-aware logic.
When to use it
- When opening files, sockets, or database connections that must be closed
- When acquiring locks or semaphores that require release
- When you need deterministic cleanup on error or interruption
- When building long-lived services with layered resources
- When composing multiple resources sequentially or in parallel
Best practices
- Use acquireRelease or acquireUseRelease for paired acquire/release patterns
- Keep finalizers simple and make them infallible; log errors instead of throwing
- Call Effect.scoped at clear boundaries (not too wide, not too narrow)
- Rely on Effect’s reverse-order finalization when composing multiple resources
- Use Layer.scoped for service-level resources tied to application lifecycle
Example use cases
- Read a file safely with acquireUseRelease to ensure the handle is closed after use
- Create a database pool with acquireRelease and expose query methods that use the pool
- Wrap a lock with acquireUseRelease to guarantee release after critical sections
- Compose acquiring DB and cache connections sequentially or in parallel inside a scoped block
- Attach logging finalizers with addFinalizer or use ensuring/onExit for exit-specific cleanup
FAQ
acquireRelease pairs an acquire and a release; use it with Effect.scoped to access the resource. acquireUseRelease combines acquire, use, and release into one call for simpler flows.
Will cleanup run if the effect is interrupted?
Yes. Finalizers registered in the Scope run on interruption, ensuring resources are released even when effects are canceled or time out.