MCPcopy Create free account
hub / github.com/Effect-TS/effect / getImpl

Function getImpl

packages/effect/src/ScopedCache.ts:359–383  ·  view source on GitHub ↗
(
  self: ScopedCache<Key, A, E, R>,
  key: Key,
  fiber: Fiber.Fiber<any, any>,
  isRead = true
)

Source from the content-addressed store, hash-verified

357)
358
359const getImpl = <Key, A, E, R>(
360 self: ScopedCache<Key, A, E, R>,
361 key: Key,
362 fiber: Fiber.Fiber<any, any>,
363 isRead = true
364): Effect.Effect<Entry<A, E> | undefined> => {
365 if (self.state._tag === "Closed") {
366 return effect.interrupt
367 }
368 const state = self.state
369 const oentry = MutableHashMap.get(state.map, key)
370 if (Option.isNone(oentry)) {
371 return effect.undefined
372 } else if (hasExpired(oentry.value, fiber)) {
373 MutableHashMap.remove(state.map, key)
374 return effect.as(
375 Scope.close(oentry.value.scope, effect.exitVoid),
376 undefined
377 )
378 } else if (isRead) {
379 MutableHashMap.remove(state.map, key)
380 MutableHashMap.set(state.map, key, oentry.value)
381 }
382 return effect.succeed(oentry.value)
383}
384
385/**
386 * Retrieves the value associated with the specified key from the cache, only if

Callers 1

ScopedCache.tsFile · 0.70

Calls 6

hasExpiredFunction · 0.70
getMethod · 0.65
closeMethod · 0.65
setMethod · 0.65
removeMethod · 0.45
succeedMethod · 0.45

Tested by

no test coverage detected