Hyperlinkv0.8.0-beta.28

ScopedCache

ScopedCache.getSuccessconsteffect/ScopedCache.ts:405
<Key, A, R>(key: Key): <E>(
  self: ScopedCache<Key, A, E, R>
) => Effect.Effect<Option.Option<A>>
<Key, A, E, R>(self: ScopedCache<Key, A, E, R>, key: Key): Effect.Effect<
  Option.Option<A>
>

Retrieves the value associated with the specified key from the cache, only if it contains a resolved successful value.

When to use

Use to inspect an already-completed successful scoped cache entry without running or awaiting the lookup effect.

Details

Returns Option.some for a resolved successful entry. Returns Option.none for missing, expired, failed, or still-pending entries.

combinatorsgetgetOption
export const getSuccess: {
  <Key, A, R>(key: Key): <E>(self: ScopedCache<Key, A, E, R>) => Effect.Effect<Option.Option<A>>
  <Key, A, E, R>(self: ScopedCache<Key, A, E, R>, key: Key): Effect.Effect<Option.Option<A>>
} = dual(
  2,
  <Key, A, E, R>(self: ScopedCache<Key, A, E, R>, key: Key): Effect.Effect<Option.Option<A>> =>
    effect.uninterruptible(
      core.withFiber((fiber) =>
        effect.map(
          getImpl(self, key, fiber),
          (entry) => {
            const exit = entry?.deferred.effect as Exit.Exit<A, E> | undefined
            if (exit && effect.exitIsSuccess(exit)) {
              return Option.some(exit.value)
            }
            return Option.none()
          }
        )
      )
    )
)