Skip to content
Effect 4.0 is here. One ecosystem. Zero dependencies.

ScopedRef

10 exports Since v2.0.0 Source

Constructors

Creates a new ScopedRef from an effect that resourcefully produces a value.

Signature

declare const fromAcquire: <A, E, R>(acquire: Effect.Effect<A, E, R>) => Effect.Effect<ScopedRef<A>, E, Scope.Scope | R>
Since v2.0.0

Creates a new ScopedRef from the specified value. This method should not be used for values whose creation require the acquisition of resources.

Signature

declare const make: <A>(evaluate: LazyArg<A>) => Effect.Effect<ScopedRef<A>, never, Scope.Scope>

Getters

Since v2.0.0

Retrieves the current value of the scoped reference.

Signature

declare const get: <A>(self: ScopedRef<A>) => Effect.Effect<A>
Since v2.0.0

Sets the value of this reference to the specified resourcefully-created value. Any resources associated with the old value will be released.

This method will not return until either the reference is successfully changed to the new value, with old resources released, or until the attempt to acquire a new value fails.

Signature

declare const set: {
<A, R, E>(acquire: Effect<A, E, R>): (self: ScopedRef<A>) => Effect<void, E, Exclude<R, Scope>>;
<A, R, E>(self: ScopedRef<A>, acquire: Effect<A, E, R>): Effect<void, E, Exclude<R, Scope>>;
}

Models

ScopedRef

interface
Since v2.0.0

A ScopedRef is a reference whose value is associated with resources, which must be released properly. You can both get the current value of any ScopedRef, as well as set it to a new value (which may require new resources). The reference itself takes care of properly releasing resources for the old value whenever a new value is obtained.

Signature

interface ScopedRef<in out A> extends Effect<A>, Variance<A>, Pipeable {
readonly [ignoreSymbol]?: ScopedRefUnifyIgnore;
readonly [typeSymbol]?: unknown;
readonly [unifySymbol]?: ScopedRefUnify<ScopedRef<A>>;
}
Since v3.9.0

Signature

interface ScopedRefUnify<A extends {
[typeSymbol]?: any;
}> extends EffectUnify<A> {
ScopedRef?: () => Extract<A[typeof typeSymbol], ScopedRef<any>>;
}
Since v3.9.0

Signature

interface ScopedRefUnifyIgnore extends EffectUnifyIgnore {
Effect?: true;
}

Other

Symbols

Signature

declare const ScopedRefTypeId: unique symbol
Since v2.0.0

Signature

type ScopedRefTypeId = typeof ScopedRefTypeId