MCPcopy Index your code
hub / github.com/Effect-TS/effect / getEither

Method getEither

packages/effect/src/internal/cache.ts:394–423  ·  view source on GitHub ↗
(key: Key)

Source from the content-addressed store, hash-verified

392 }
393
394 getEither(key: Key): Effect.Effect<Either.Either<Value, Value>, Error> {
395 return core.suspend((): Effect.Effect<Either.Either<Value, Value>, Error> => {
396 const k = key
397 let mapKey: MapKey<Key> | undefined = undefined
398 let deferred: Deferred.Deferred<Value, Error> | undefined = undefined
399 let value = Option.getOrUndefined(MutableHashMap.get(this.cacheState.map, k))
400 if (value === undefined) {
401 deferred = Deferred.unsafeMake<Value, Error>(this.fiberId)
402 mapKey = makeMapKey(k)
403 if (MutableHashMap.has(this.cacheState.map, k)) {
404 value = Option.getOrUndefined(MutableHashMap.get(this.cacheState.map, k))
405 } else {
406 MutableHashMap.set(this.cacheState.map, k, pending(mapKey, deferred))
407 }
408 }
409 if (value === undefined) {
410 this.trackAccess(mapKey!)
411 this.trackMiss()
412 return core.map(this.lookupValueOf(key, deferred!), Either.right)
413 } else {
414 return core.flatMap(
415 this.resolveMapValue(value),
416 Option.match({
417 onNone: () => this.getEither(key),
418 onSome: (value) => core.succeed(Either.left(value))
419 })
420 )
421 }
422 })
423 }
424
425 invalidate(key: Key): Effect.Effect<void> {
426 return core.sync(() => {

Callers 1

getMethod · 0.95

Calls 9

trackAccessMethod · 0.95
trackMissMethod · 0.95
lookupValueOfMethod · 0.95
resolveMapValueMethod · 0.95
makeMapKeyFunction · 0.85
pendingFunction · 0.70
getMethod · 0.65
setMethod · 0.65
mapMethod · 0.65

Tested by

no test coverage detected