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

Function runShared

packages/effect/src/ui/Query.ts:6143–6199  ·  view source on GitHub ↗
(shared: Shared, restart: boolean)

Source from the content-addressed store, hash-verified

6141 * fetch it was converted from, or its own fetch under a build that closed.
6142 */
6143 const runShared = (shared: Shared, restart: boolean): void => {
6144 emitFetch(
6145 shared.entry,
6146 "get",
6147 restart,
6148 false,
6149 shared.entry.def.list === undefined
6150 ? undefined
6151 : { page: 0, cursor: undefined }
6152 )
6153 const build = shared.build
6154 const previous: Array<Fiber.Fiber<any, any>> = []
6155 const stored = draining.get(drainKey(shared.entry))
6156 if (stored !== undefined) previous.push(stored)
6157 const replaced = shared.fiber
6158 if (replaced !== undefined) {
6159 // Cleared first, so the replaced fiber's exit doesn't end the callers' fetch.
6160 shared.fiber = undefined
6161 replaced.interruptUnsafe()
6162 previous.push(replaced)
6163 }
6164 const entry = shared.entry
6165 const walk = entry.def.list?.ops.callerWalk(
6166 cacheEnv(),
6167 entry.def,
6168 entry.args,
6169 () => logKeyOf(entry),
6170 build,
6171 Math.max(entry.def.list.ops.heldPages(entry).length, 1),
6172 (page, cursor) => {
6173 if (shared.fiber === fiber) {
6174 emitFetch(entry, "get", false, false, { page, cursor }, requestParent)
6175 }
6176 }
6177 )
6178 const fiber = runFork(Effect.andThen(
6179 previous.length === 0
6180 ? Effect.yieldNow
6181 : Effect.uninterruptible(Fiber.awaitAll(previous)),
6182 traced(
6183 entry.def,
6184 "get",
6185 () =>
6186 walk ??
6187 fetchOnce(entry.def, build, entry.args, () => logKeyOf(entry)),
6188 requestParent
6189 )
6190 ))
6191 shared.fiber = fiber
6192 fetchFibers.add(fiber)
6193 build.fibers.add(fiber)
6194 fiber.addObserver((exit) => {
6195 fetchFibers.delete(fiber)
6196 build.fibers.delete(fiber)
6197 if (shared.fiber === fiber && !disposed) endShared(shared, exit)
6198 })
6199 }
6200 /** Hands the exit to the callers. Nothing is stored and the entry doesn't change. */

Callers 2

buildClosedFunction · 0.85
startSharedFunction · 0.85

Calls 14

emitFetchFunction · 0.85
drainKeyFunction · 0.85
cacheEnvFunction · 0.85
logKeyOfFunction · 0.85
runForkFunction · 0.85
fetchOnceFunction · 0.85
endSharedFunction · 0.85
addObserverMethod · 0.80
tracedFunction · 0.70
getMethod · 0.65
pushMethod · 0.65
addMethod · 0.65

Tested by

no test coverage detected