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

Function get

packages/effect/src/ui/Query.ts:6472–6546  ·  view source on GitHub ↗
(def, args, fetcher, run, parent)

Source from the content-addressed store, hash-verified

6470
6471 // The order of checks: own target, hydration window, live patch, staleness.
6472 const get: CacheInternals["get"] = (def, args, fetcher, run, parent) =>
6473 Effect.suspend((): Effect.Effect<any, any> => {
6474 if (disposed) return Effect.interrupt
6475 const registered = register(def)
6476 // Its fetch never starts.
6477 if (offServer(registered)) return Effect.interrupt
6478 const argsKey = registered.argsKey(args)
6479 // A started run reading back an entry it invalidates calls the fetcher itself: never from the store, never
6480 // joined and never stored.
6481 if (
6482 run !== undefined && run.isStarted() &&
6483 run.invalidates(registered, argsKey)
6484 ) {
6485 const existing = lookup(registered, argsKey)
6486 const logKey = () => registered.logKey(args, argsKey)
6487 const event = (page: PageRef | undefined): void => {
6488 if (existing !== undefined) {
6489 return emitFetch(existing, "get", false, false, page, parent)
6490 }
6491 if (fetchListeners.size === 0) return
6492 notify<FetchEvent>(fetchListeners, {
6493 query: registered.name,
6494 logKey: logKey(),
6495 trigger: "get",
6496 restart: false,
6497 inWindow: false,
6498 stored: false,
6499 empty: true,
6500 ...pageFields(page),
6501 ...spanFields(parent)
6502 })
6503 }
6504 if (existing !== undefined) resetIdle(existing)
6505 const list = registered.list
6506 const build = buildOf(fetcher)
6507 event(list === undefined ? undefined : { page: 0, cursor: undefined })
6508 return traced(registered, "get", () =>
6509 list === undefined
6510 ? fetchOnce(registered, build, args, logKey)
6511 : list.ops.callerWalk(
6512 cacheEnv(),
6513 registered,
6514 args,
6515 logKey,
6516 build,
6517 existing === undefined
6518 ? 1
6519 : Math.max(list.ops.heldPages(existing).length, 1),
6520 (page, cursor) => event({ page, cursor })
6521 ), "caller")
6522 }
6523 const entry = ensureEntry(registered, args, argsKey)
6524 const result = entry.result
6525 if (result !== undefined && (inWindow(entry) || settleOnce)) {
6526 resetIdle(entry)
6527 return settledEffect(result)
6528 }
6529 const build = buildOf(fetcher)

Callers

nothing calls this directly

Calls 15

offServerFunction · 0.85
resetIdleFunction · 0.85
buildOfFunction · 0.85
fetchOnceFunction · 0.85
cacheEnvFunction · 0.85
ensureEntryFunction · 0.85
settledEffectFunction · 0.85
getStoredFunction · 0.85
hasLiveFunction · 0.85
getSharedFunction · 0.85
registerFunction · 0.70
lookupFunction · 0.70

Tested by

no test coverage detected