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

Method lookupValueOf

packages/effect/src/internal/scopedCache.ts:441–513  ·  view source on GitHub ↗
(key: Key)

Source from the content-addressed store, hash-verified

439 }
440
441 lookupValueOf(key: Key): Effect.Effect<Effect.Effect<Value, Error, Scope.Scope>> {
442 return pipe(
443 core.onInterrupt(
444 core.flatMap(Scope.make(), (scope) =>
445 pipe(
446 this.scopedLookup(key),
447 core.provideContext(pipe(this.context, Context.add(Scope.Scope, scope))),
448 core.exit,
449 core.map((exit) => [exit, ((exit) => Scope.close(scope, exit)) as Scope.Scope.Finalizer] as const)
450 )),
451 () => core.sync(() => MutableHashMap.remove(this.cacheState.map, key))
452 ),
453 core.flatMap(([exit, release]) => {
454 const now = this.clock.unsafeCurrentTimeMillis()
455 const expiredAt = now + Duration.toMillis(this.timeToLive(exit))
456 switch (exit._tag) {
457 case "Success": {
458 const exitWithFinalizer: Exit.Exit<[Value, Scope.Scope.Finalizer]> = Exit.succeed([
459 exit.value,
460 release
461 ])
462 const completedResult = complete<Key, Value, Error>(
463 cache_.makeMapKey(key),
464 exitWithFinalizer,
465 MutableRef.make(1),
466 cache_.makeEntryStats(now),
467 expiredAt
468 )
469 let previousValue: MapValue<Key, Value, Error> | undefined = undefined
470 if (MutableHashMap.has(this.cacheState.map, key)) {
471 previousValue = Option.getOrUndefined(MutableHashMap.get(this.cacheState.map, key))
472 }
473 MutableHashMap.set(this.cacheState.map, key, completedResult)
474 return core.sync(() =>
475 core.flatten(
476 core.as(
477 this.cleanMapValue(previousValue),
478 toScoped(completedResult)
479 )
480 )
481 )
482 }
483 case "Failure": {
484 const completedResult = complete<Key, Value, Error>(
485 cache_.makeMapKey(key),
486 exit as Exit.Exit<readonly [Value, Scope.Scope.Finalizer], Error>,
487 MutableRef.make(0),
488 cache_.makeEntryStats(now),
489 expiredAt
490 )
491 let previousValue: MapValue<Key, Value, Error> | undefined = undefined
492 if (MutableHashMap.has(this.cacheState.map, key)) {
493 previousValue = Option.getOrUndefined(MutableHashMap.get(this.cacheState.map, key))
494 }
495 MutableHashMap.set(this.cacheState.map, key, completedResult)
496 return core.zipRight(
497 release(exit),
498 core.sync(() =>

Callers 2

getMethod · 0.95
refreshMethod · 0.95

Calls 14

cleanMapValueMethod · 0.95
toScopedFunction · 0.85
syncMethod · 0.80
pipeFunction · 0.70
completeFunction · 0.70
releaseFunction · 0.70
makeMethod · 0.65
addMethod · 0.65
mapMethod · 0.65
closeMethod · 0.65
removeMethod · 0.65

Tested by

no test coverage detected