Table of Contents

Class PaletteLoadCoordinator

Namespace
EncDotNet.S100.Portrayals
Assembly
EncDotNet.S100.Portrayals.dll

Centralizes the concurrency-safe, one-shot colour-palette load protocol shared by every portrayal catalogue.

public static class PaletteLoadCoordinator
Inheritance
PaletteLoadCoordinator
Inherited Members

Remarks

A single IPortrayalAssetCache is shared per product spec across every dataset of that spec (for example, every cell of one S-101 exchange set), and those datasets load on separate threads. Two earlier defects followed from loading palettes ad hoc:

  1. Cache poisoning. Marking PalettesLoaded before the load completed meant a cancelled or aborted load (routine in the viewer when a pan/zoom/reload cancels the in-flight render) left the shared cache flagged loaded-but-empty, so every later palette lookup failed.
  2. Races. Concurrent loaders wrote the non-thread-safe palette dictionary simultaneously, or a second loader observed it half-populated.

This helper serializes the load through PaletteLoadGate with double-checked locking and commits PalettesLoaded only after the load runs to completion without being cancelled. See issue #321.

Methods

EnsureLoadedAsync(IPortrayalAssetCache, Func<CancellationToken, ValueTask>, Action, CancellationToken)

Ensures the shared cache's palettes are loaded exactly once, safely under concurrency, retrying after a cancelled attempt rather than poisoning the cache.

public static ValueTask EnsureLoadedAsync(IPortrayalAssetCache cache, Func<CancellationToken, ValueTask> loadInto, Action onLoaded, CancellationToken cancellationToken = default)

Parameters

cache IPortrayalAssetCache

The shared per-spec asset cache.

loadInto Func<CancellationToken, ValueTask>

Populates Palettes. Invoked at most once per successful load while the gate is held. Must not set PalettesLoaded itself.

onLoaded Action

Applies the catalogue's active-palette selection (typically Day). Called after the load completes and on the already-loaded fast path.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask