(onCause)
| 6345 | // Each entry whose last watcher left with `abandon` during the hold. |
| 6346 | const abandoned = new Set<Entry>() |
| 6347 | const hold: CacheInternals["hold"] = (onCause) => { |
| 6348 | if (holds++ === 0) generation++ |
| 6349 | holdCause ??= onCause |
| 6350 | const since = generation |
| 6351 | let released = false |
| 6352 | return () => { |
| 6353 | if (released) return |
| 6354 | released = true |
| 6355 | if (holds > 1) { |
| 6356 | holds-- |
| 6357 | return |
| 6358 | } |
| 6359 | // Still held while deciding: a fetch started here can reach a watcher whose handler registers another, |
| 6360 | // which is decided in the next round, as part of this hold. |
| 6361 | while (held.size > 0 || abandoned.size > 0) { |
| 6362 | // Registrations first: deciding one can start a fetch whose handler takes an abandoned fetch over. |
| 6363 | if (held.size === 0) { |
| 6364 | for (const entry of abandoned) { |
| 6365 | abandoned.delete(entry) |
| 6366 | if (!entry.removed) abandonFetch(entry) |
| 6367 | } |
| 6368 | continue |
| 6369 | } |
| 6370 | const entries = Array.from(held) |
| 6371 | held.clear() |
| 6372 | for (const entry of entries) { |
| 6373 | if (entry.removed || entry.watchers.size === 0) continue |
| 6374 | let build: Build | undefined |
| 6375 | let watcherPath: string | undefined |
| 6376 | let fresh = true |
| 6377 | // Only the watchers that survive count: one that registered inside the window and left is gone. |
| 6378 | let windowed = false |
| 6379 | let withheld = false |
| 6380 | let seen = false |
| 6381 | let hasCause = false |
| 6382 | let cause: number | undefined |
| 6383 | const onCause = holdCause |
| 6384 | for (const watcher of entry.watchers) { |
| 6385 | if (watcher.generation < since) fresh = false |
| 6386 | else { |
| 6387 | if (watcher.windowed) windowed = true |
| 6388 | if (onCause !== undefined) { |
| 6389 | watcherPath ??= watcher.path |
| 6390 | // Distinct causes cannot be attributed to a single render. |
| 6391 | if (!hasCause) { |
| 6392 | hasCause = true |
| 6393 | cause = watcher.cause |
| 6394 | } else if (cause !== watcher.cause) cause = undefined |
| 6395 | } |
| 6396 | } |
| 6397 | if ( |
| 6398 | watcher.provisional !== undefined && |
| 6399 | watcher.provisional === entry.result |
| 6400 | ) withheld = true |
| 6401 | else seen = true |
| 6402 | watcher.provisional = undefined |
| 6403 | if (build === undefined && !watcher.build.closed) { |
| 6404 | build = watcher.build |
nothing calls this directly
no test coverage detected