RcRef overview
Added in v3.5.0
Table of contents
combinators
get
Signature
export declare const get: <A, E>(self: RcRef<A, E>) => Effect.Effect<A, E, Scope.Scope>
Added in v3.5.0
constructors
make
Create an RcRef
from an acquire Effect
.
An RcRef wraps a reference counted resource that can be acquired and released multiple times.
The resource is lazily acquired on the first call to get
and released when the last reference is released.
Signature
export declare const make: <A, E, R>(options: {
readonly acquire: Effect.Effect<A, E, R>
readonly idleTimeToLive?: Duration.DurationInput | undefined
}) => Effect.Effect<RcRef<A, E>, never, R | Scope.Scope>
Example
import { Effect, RcRef } from "effect"
Effect.gen(function* () {
const ref = yield* RcRef.make({
acquire: Effect.acquireRelease(Effect.succeed("foo"), () => Effect.log("release foo"))
})
// will only acquire the resource once, and release it
// when the scope is closed
yield* RcRef.get(ref).pipe(Effect.andThen(RcRef.get(ref)), Effect.scoped)
})
Added in v3.5.0
models
RcRef (interface)
Signature
export interface RcRef<out A, out E = never>
extends Effect.Effect<A, E, Scope.Scope>,
Readable.Readable<A, E, Scope.Scope> {
readonly [TypeId]: RcRef.Variance<A, E>
readonly [Unify.typeSymbol]?: unknown
readonly [Unify.unifySymbol]?: RcRefUnify<this>
readonly [Unify.ignoreSymbol]?: RcRefUnifyIgnore
}
Added in v3.5.0
RcRef (namespace)
Added in v3.5.0
Variance (interface)
Signature
export interface Variance<A, E> {
readonly _A: Types.Covariant<A>
readonly _E: Types.Covariant<E>
}
Added in v3.5.0
RcRefUnify (interface)
Signature
export interface RcRefUnify<A extends { [Unify.typeSymbol]?: any }> extends Effect.EffectUnify<A> {
RcRef?: () => A[Unify.typeSymbol] extends RcRef<infer A0, infer E0> | infer _ ? RcRef<A0, E0> : never
}
Added in v3.8.0
RcRefUnifyIgnore (interface)
Signature
export interface RcRefUnifyIgnore extends Effect.EffectUnifyIgnore {
Effect?: true
}
Added in v3.8.0
type ids
TypeId
Signature
export declare const TypeId: typeof TypeId
Added in v3.5.0
TypeId (type alias)
Signature
export type TypeId = typeof TypeId
Added in v3.5.0