Hyperlinkv0.8.0-beta.28

ScopedRef

ScopedRef.setconsteffect/ScopedRef.ts:171
<A, R, E>(acquire: Effect.Effect<A, E, R>): (
  self: ScopedRef<A>
) => Effect.Effect<void, E, Exclude<R, Scope.Scope>>
<A, R, E>(
  self: ScopedRef<A>,
  acquire: Effect.Effect<A, E, R>
): Effect.Effect<void, E, Exclude<R, Scope.Scope>>

Sets the value of this reference to a newly acquired scoped value, releasing any resources associated with the old value.

When to use

Use to replace the current value of an existing ScopedRef with a newly acquired scoped value while releasing resources for the previous value.

Details

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.

setters
export const set: {
  <A, R, E>(acquire: Effect.Effect<A, E, R>): (self: ScopedRef<A>) => Effect.Effect<void, E, Exclude<R, Scope.Scope>>
  <A, R, E>(self: ScopedRef<A>, acquire: Effect.Effect<A, E, R>): Effect.Effect<void, E, Exclude<R, Scope.Scope>>
} = dual(
  2,
  Effect.fnUntraced(
    function*<A, R, E>(
      self: ScopedRef<A>,
      acquire: Effect.Effect<A, E, R>
    ) {
      yield* Scope.close(self.backing.backing.ref.current[0], Exit.void)
      const scope = Scope.makeUnsafe()
      const value = yield* acquire.pipe(
        Scope.provide(scope),
        Effect.tapCause((cause) => Scope.close(scope, Exit.failCause(cause)))
      )
      self.backing.backing.ref.current = [scope, value]
    },
    Effect.uninterruptible,
    (effect, self) => self.backing.semaphore.withPermit(effect)
  )
)
Referenced by 1 symbols