The load's abort checks: one step instead of 22 by hand

Merged
AL
1d ago
+114-53

Closes #327.

  • src/abortable.ts: abortable(signal) returns a step(value), written step(await …), that hands the awaited value on, or throws the signal's reason once the load is aborted. Every await in startLoad, downloadAndIndex, index, supplyParts and supplyLibraries is written that way.
  • 22 signal.aborted checks become 7, each one deciding something: a catch that stops retrying once aborted, startLoad's silence for a replaced load, and the tryBoot guard.
  • Fixes two places a replaced load wrote over its successor: supplyParts set internalLibraryBundle, and supplyLibraries' fallback set the state, the held package and internalLibraryBundle, each after an await with no check.
  • design/element.md: new rule Every await of a load is written step(await …).

Changed after my review of the first version

  • Its step(promise) was a promise of its own, awaited as await step(…), so the load resumed one turn after the answer. A new src set in that turn was missed, and the replaced load wrote its state on: the kind of bug this pull request is here to end. The check now runs in the turn the await resumes in, as the hand-placed checks did; a test holds that turn.
  • So a replaced load does not stop "at once", as #327 put it. It stops when the step it waits on settles, as on main; the long steps (a download, the warm, the pack's parts) settle on the abort themselves.
  • Five awaits the first version left outside the step are inside it, so the rule is true of the code: both supplyParts calls, supplyLibraries, its probeSource, and partPkgId.

Tests: tests/unit/abortable.test.ts (4); the player's whole suite passes locally (633). Under #326's config the changed files lint clean but for one await-thenable, on if (attempt) step(await attempt): the finding #326 disables on that line. The two conflict there, so after #326 merges I'll rebase this one and keep its comment.


Summary by cubic

Replaces the load path's 22 hand-placed signal.aborted checks with one abortable(signal) helper from src/abortable.ts. Every await in the load now goes through step(promise), which settles as the promise does or rejects with the signal's reason the moment the load is aborted — so nothing after an await runs for a replaced load.

Also fixes two spots where a replaced load wrote over its successor: supplyParts set internalLibraryBundle, and supplyLibraries' fallback set the state, held package, and internalLibraryBundle after an await with no check.

Notes

  • The remaining 7 checks each decide something: a catch that stops retrying once aborted, startLoad's silence for a replaced load, and the tryBoot guard.
  • Adds tests/unit/abortable.test.ts and a rule in design/element.md that every await of a load goes through its step.