The load's abort checks: one step instead of 22 by hand
Closes #327.
src/abortable.ts:abortable(signal)returns astep(value), writtenstep(await …), that hands the awaited value on, or throws the signal's reason once the load is aborted. Every await instartLoad,downloadAndIndex,index,supplyPartsandsupplyLibrariesis written that way.- 22
signal.abortedchecks become 7, each one deciding something: acatchthat stops retrying once aborted,startLoad's silence for a replaced load, and thetryBootguard. - Fixes two places a replaced load wrote over its successor:
supplyPartssetinternalLibraryBundle, andsupplyLibraries' fallback set the state, the held package andinternalLibraryBundle, each after an await with no check. design/element.md: new rule Every await of a load is writtenstep(await …).
Changed after my review of the first version
- Its
step(promise)was a promise of its own, awaited asawait step(…), so the load resumed one turn after the answer. A newsrcset 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
supplyPartscalls,supplyLibraries, itsprobeSource, andpartPkgId.
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
catchthat stops retrying once aborted,startLoad's silence for a replaced load, and thetryBootguard. - Adds
tests/unit/abortable.test.tsand a rule indesign/element.mdthat every await of a load goes through itsstep.