<A, E>(self: RcRef<A, E>): Effect.Effect<void>Invalidates the currently cached resource, if one has been acquired.
When to use
Use to force future RcRef.get calls to acquire a fresh resource when the
currently cached resource should no longer be reused.
Details
After invalidation, the next get acquires a fresh resource.
Gotchas
Invalidation does not revoke resources already borrowed by active scopes; those remain usable until their scopes close.
export const const invalidate: <A, E>(
self: RcRef<A, E>
) => Effect.Effect<void>
Invalidates the currently cached resource, if one has been acquired.
When to use
Use to force future RcRef.get calls to acquire a fresh resource when the
currently cached resource should no longer be reused.
Details
After invalidation, the next get acquires a fresh resource.
Gotchas
Invalidation does not revoke resources already borrowed by active scopes;
those remain usable until their scopes close.
invalidate: <function (type parameter) A in <A, E>(self: RcRef<A, E>): Effect.Effect<void>A, function (type parameter) E in <A, E>(self: RcRef<A, E>): Effect.Effect<void>E>(self: RcRef<A, E>(parameter) self: {
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self: interface RcRef<out A, out E = never>A reference counted reference that manages resource lifecycle.
When to use
Use to share a scoped resource across active users with reference-counted
acquisition and release.
Details
An RcRef wraps a resource that can be acquired and released multiple times.
The resource is lazily acquired on the first call to get and automatically
released when the last reference is released.
Example (Sharing a lazily acquired resource)
import { Effect, RcRef } from "effect"
// Create an RcRef for a database connection
const createConnectionRef = (connectionString: string) =>
RcRef.make({
acquire: Effect.acquireRelease(
Effect.succeed(`Connected to ${connectionString}`),
(connection) => Effect.log(`Closing connection: ${connection}`)
)
})
// Use the RcRef in multiple operations
const program = Effect.gen(function*() {
const connectionRef = yield* createConnectionRef("postgres://localhost")
// Multiple gets will share the same connection
const connection1 = yield* RcRef.get(connectionRef)
const connection2 = yield* RcRef.get(connectionRef)
return [connection1, connection2]
})
Namespace containing type-level members associated with RcRef.
Example (Referencing namespace types)
import type { RcRef } from "effect"
// Use RcRef namespace types
type MyRcRef = RcRef.RcRef<string, Error>
type MyVariance = RcRef.RcRef.Variance<string, Error>
RcRef<function (type parameter) A in <A, E>(self: RcRef<A, E>): Effect.Effect<void>A, function (type parameter) E in <A, E>(self: RcRef<A, E>): Effect.Effect<void>E>) => import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<void> = import internalinternal.const invalidate: <A, E>(
self_: RcRef.RcRef<A, E>
) => Effect.Effect<void>
invalidate