Skip to main content Link Search Menu Expand Document (external link)

RcRef.ts overview

Since v3.5.0


Exports Grouped by Category


combinators

get

Signature

declare const get: <A, E>(self: RcRef<A, E>) => Effect.Effect<A, E, Scope.Scope>

Source

Since 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.

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)
})

Signature

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>

Source

Since 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
}

Source

Since v3.5.0

RcRef (namespace)

Source

Since v3.5.0

Variance (interface)

Signature

export interface Variance<A, E> {
  readonly _A: Types.Covariant<A>
  readonly _E: Types.Covariant<E>
}

Source

Since 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
}

Source

Since v3.8.0

RcRefUnifyIgnore (interface)

Signature

export interface RcRefUnifyIgnore extends Effect.EffectUnifyIgnore {
  Effect?: true
}

Source

Since v3.8.0

type ids

TypeId

Signature

declare const TypeId: unique symbol

Source

Since v3.5.0

TypeId (type alias)

Signature

type TypeId = typeof TypeId

Source

Since v3.5.0