Resource safety with acquireRelease, Effect.scoped, and finalizers. Use when opening files, sockets, servers, or external handles.
const withConn = Effect.acquireRelease(
Effect.sync(() => open()),
(conn) => Effect.sync(() => close(conn))
).pipe(Effect.flatMap(use))
yield* Effect.scoped(
Effect.gen(function* () {
const h = yield* Effect.acquireRelease(acquire(), release)
return yield* use(h)
})
)
yield* Effect.addFinalizer(() => cleanup)
operation.pipe(Effect.ensuring(cleanup))
const wrapS3Promise = <T>(promise: Promise<T> | Effect.Effect<Promise<T>>) =>
Effect.gen(function* () {
if (promise instanceof Promise) {
return yield* Effect.tryPromise({ try: () => promise, catch: (cause) => new S3Error({ cause }) })
}
return yield* promise.pipe(
Effect.flatMap((cb) =>
Effect.tryPromise({ try: () => cb, catch: (cause) => new S3Error({ cause }) })
)
)
}).pipe(Effect.catchTag("UnknownException", (cause) => new S3Error({ cause })))
// Usage with spans
const put = wrapS3Promise(client.send(new S3.PutObjectCommand(args))).pipe(
Effect.withSpan("S3.putObject", { attributes: { key: args.Key } })
)
CRITICAL: Search local Effect source before implementing
The full Effect source code is available at docs/effect-source/. Always search the actual implementation before writing Effect code.
docs/effect-source/effect/src/Effect.tsdocs/effect-source/effect/src/Scope.ts# Find acquireRelease patterns
grep -F "acquireRelease" docs/effect-source/effect/src/Effect.ts
# Study scoped operations
grep -F "scoped" docs/effect-source/effect/src/Effect.ts
grep -F "addFinalizer" docs/effect-source/effect/src/Effect.ts
# Find ensuring patterns
grep -F "ensuring" docs/effect-source/effect/src/Effect.ts
# Look at Scope implementation
grep -F "export" docs/effect-source/effect/src/Scope.ts | grep -F "function"
docs/effect-source/effect/src/Effect.ts for the implementationReal source code > documentation > assumptions
npx skills add mepuka/effect-resources-scope下载完整 Skill 目录,包含 SKILL.md 及所有相关文件
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer