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

Function lookup

packages/effect/src/Context.ts:531–547  ·  view source on GitHub ↗
(self: Context<any>, key: string)

Source from the content-addressed store, hash-verified

529const notFound = Symbol()
530
531const lookup = (self: Context<any>, key: string): unknown => {
532 const impl = self as ContextImpl<any>
533 for (let overlay = impl.overlay; overlay; overlay = overlay.parent) {
534 if (overlay.key === key) return overlay.value
535 }
536 const value = impl.base.get(key)
537 // Misses must not advance the counter: reference-default lookups miss the
538 // base on every fiber cache refresh, which would flatten every short-lived
539 // request context and reintroduce the O(services) per-request cost
540 if (value === undefined && !impl.base.has(key)) return notFound
541 if (impl.overlay && ++impl.baseHits >= FlattenAfterBaseHits) {
542 impl.base = flatten(impl)
543 impl.overlay = undefined
544 impl.depth = 0
545 }
546 return value
547}
548
549/**
550 * Creates a `Context` from an existing service map.

Callers 6

LayerMap.tsFile · 0.70
makeWithFunction · 0.70
Context.tsFile · 0.70
getOrUndefinedUnsafeFunction · 0.70
PersistedCache.tsFile · 0.50
ResourceMapClass · 0.50

Calls 3

flattenFunction · 0.70
getMethod · 0.65
hasMethod · 0.45

Tested by

no test coverage detected