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

Function startFetch

packages/effect/src/ui/Query.ts:5868–5936  ·  view source on GitHub ↗
(
    entry: Entry,
    trigger: Trigger,
    build: Build,
    restart: boolean,
    append = false,
    parent?: queryCore.SpanContext | undefined,
    watcher?: string | undefined
  )

Source from the content-addressed store, hash-verified

5866
5867 // -- fetching ---------------------------------------------------------------
5868 const startFetch = (
5869 entry: Entry,
5870 trigger: Trigger,
5871 build: Build,
5872 restart: boolean,
5873 append = false,
5874 parent?: queryCore.SpanContext | undefined,
5875 watcher?: string | undefined
5876 ): void => {
5877 if (entry.heldRestart && !append) {
5878 entry.heldRestart = false
5879 restart = true
5880 }
5881 // A stream still open closes: its successor waits for its cleanup.
5882 if (entry.live !== undefined) dropFetch(entry)
5883 // A stream's span lasts as long as the stream, so it never joins a Command's trace.
5884 const effectiveParent = (entry.def.live === undefined ? parent : undefined) ??
5885 requestParent
5886 const fetch: FetchRec = {
5887 trigger,
5888 build,
5889 fiber: undefined,
5890 append,
5891 parent: effectiveParent,
5892 watcher
5893 }
5894 entry.fetch = fetch
5895 if (!idleEligible(entry)) cancelIdle(entry)
5896 const live = entry.def.live
5897 let body: () => Effect.Effect<any, any> = live === undefined
5898 ? () => build.fetcher(entry.args)
5899 : () => live.body(cacheEnv(), entry, fetch, build)
5900 let page: PageRef | undefined
5901 if (entry.def.list !== undefined) {
5902 ;({ body, page } = entry.def.list.ops.prepareFetch(
5903 cacheEnv(),
5904 entry,
5905 fetch,
5906 trigger,
5907 build,
5908 append
5909 ))
5910 }
5911 // Reported before the entry turns ordinary, so the event says whether it fetched inside the window.
5912 emitFetch(entry, trigger, restart, true, page, effectiveParent, watcher)
5913 // A fetch after hydration makes the entry ordinary: a `get` joins it.
5914 entry.hydrated = false
5915 // The fetcher never starts inside the call that asked for it, nor before the fetch it replaces has finished
5916 // its cleanup. The wait is uninterruptible, so a chain of restarts still ends in order.
5917 const key = drainKey(entry)
5918 const previous = draining.get(key)
5919 const fiber = runFork(Effect.andThen(
5920 previous === undefined
5921 ? Effect.yieldNow
5922 : Effect.uninterruptible(Fiber.await(previous)),
5923 traced(entry.def, trigger, body, effectiveParent)
5924 ))
5925 fetch.fiber = fiber

Callers 2

ensureFetchFunction · 0.85
replaceFetchFunction · 0.85

Calls 15

dropFetchFunction · 0.85
idleEligibleFunction · 0.85
cancelIdleFunction · 0.85
cacheEnvFunction · 0.85
emitFetchFunction · 0.85
drainKeyFunction · 0.85
runForkFunction · 0.85
onFetchExitFunction · 0.85
addObserverMethod · 0.80
tracedFunction · 0.70
notifyFunction · 0.70
emitFunction · 0.70

Tested by

no test coverage detected