@crombolo/render 0.38.1 → 0.39.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/published-cache.ts +27 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/render",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.39.1",
|
|
4
4
|
"description": "Internal to crombolo, with no compatibility promise: use @crombolo/crombolo. TSX server rendering and the published-content model for crombolo.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Crombolo",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@crombolo/common": "0.
|
|
38
|
-
"@crombolo/core": "0.
|
|
37
|
+
"@crombolo/common": "0.39.1",
|
|
38
|
+
"@crombolo/core": "0.39.1",
|
|
39
39
|
"@types/react": "^19.3.0"
|
|
40
40
|
}
|
|
41
41
|
}
|
package/src/published-cache.ts
CHANGED
|
@@ -369,6 +369,8 @@ export class PublishedCache {
|
|
|
369
369
|
/** Moves on every invalidation, so a build that one overtook is not kept as current. */
|
|
370
370
|
#generation = 0
|
|
371
371
|
#building: { generation: number; done: Promise<CacheSnapshot> } | undefined
|
|
372
|
+
/** The build queued behind the one in flight, shared by everything waiting for it. */
|
|
373
|
+
#next: Promise<CacheSnapshot> | undefined
|
|
372
374
|
#snapshotGeneration = -1
|
|
373
375
|
/** A checkpoint past the snapshot's own that it is known to hold, every change between being media only. */
|
|
374
376
|
#coveredTo: number | undefined
|
|
@@ -387,15 +389,16 @@ export class PublishedCache {
|
|
|
387
389
|
|
|
388
390
|
/**
|
|
389
391
|
* The current snapshot, building it if it was dropped. The reader that starts
|
|
390
|
-
* a build waits for it; readers arriving while
|
|
391
|
-
* the previous snapshot rather than waiting
|
|
392
|
-
* build there is none, so they share the build.
|
|
392
|
+
* a build, or queues the one after it, waits for it; readers arriving while
|
|
393
|
+
* one builds are answered from the previous snapshot rather than waiting
|
|
394
|
+
* (story 175). Before the first build there is none, so they share the build.
|
|
393
395
|
*/
|
|
394
396
|
async snapshot(): Promise<CacheSnapshot> {
|
|
395
397
|
if (this.#loaded) return this.#snapshot
|
|
396
398
|
const generation = this.#generation
|
|
397
|
-
|
|
398
|
-
|
|
399
|
+
const previous = this.#snapshotGeneration >= 0 ? this.#snapshot : undefined
|
|
400
|
+
if (this.#building?.generation === generation) return previous ?? this.#building.done
|
|
401
|
+
if (this.#building) return this.#next && previous ? previous : this.#followUp()
|
|
399
402
|
return this.#start(generation)
|
|
400
403
|
}
|
|
401
404
|
|
|
@@ -409,9 +412,28 @@ export class PublishedCache {
|
|
|
409
412
|
if (this.#loaded) return this.#snapshot
|
|
410
413
|
const generation = this.#generation
|
|
411
414
|
if (this.#building?.generation === generation) return this.#building.done
|
|
415
|
+
if (this.#building) return this.#followUp()
|
|
412
416
|
return this.#start(generation)
|
|
413
417
|
}
|
|
414
418
|
|
|
419
|
+
/**
|
|
420
|
+
* One build after the one in flight, for whatever changed meanwhile: a burst
|
|
421
|
+
* of changes shares it rather than each starting a build of its own that
|
|
422
|
+
* would compete with the rest.
|
|
423
|
+
*/
|
|
424
|
+
#followUp(): Promise<CacheSnapshot> {
|
|
425
|
+
this.#next ??= (this.#building?.done ?? Promise.resolve())
|
|
426
|
+
.catch(() => undefined)
|
|
427
|
+
.then(() => {
|
|
428
|
+
this.#next = undefined
|
|
429
|
+
if (this.#loaded) return this.#snapshot
|
|
430
|
+
const generation = this.#generation
|
|
431
|
+
if (this.#building?.generation === generation) return this.#building.done
|
|
432
|
+
return this.#start(generation)
|
|
433
|
+
})
|
|
434
|
+
return this.#next
|
|
435
|
+
}
|
|
436
|
+
|
|
415
437
|
/**
|
|
416
438
|
* Builds for `generation`. A build an invalidation overtook still answers,
|
|
417
439
|
* but the next read builds again.
|