Wait for tracks to be fully drawn before returning to caller #1844
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Nice project! Thanks for sharing this (⌒‿⌒)
This PR fixes two things (the 2nd fix depends on the 1st fix, I can open a new PR if we decide to take the middleground).
The first is a regression on
TrackView#renderSVGContext
which errors out because of a missingSampleInfo#isInitialized()
, I implemented it.The second one is a more aggressive change. I will explain my reasoning below:
Problem
I wanted to write a pipeline to automatically generate SVG without human intervention. However the current implementation does not wait for the tracks to be loaded before returning to the caller, so I have no reliable way to tell when should I take the SVG.
Fix
I added
await
's to theupdateViews()
call. Caller can decide whether they want blocking behavior by awaiting or floating the API Promise as a whole, I don't think we need this level of granularity because in this (load -> draw -> display) sequence, as a user I cannot think of a reason I have to know when is only the first step done.I also removed the undocumented sync option, it is not used or mentioned anywhere and the current infrastructure made it impossible to change for ex. the ruler to sync. If we really want this level of customization I think an
async
option is better, by default we wait for the updates on these tracks to be done before resolving (which I think is a more natural behavior by common sense: an API that returns a Promise I would expect it to be done with everything before telling me "I'm done!" unless I say otherwise), and advanced users can selectively make some tracks update untracked (for perf reasons?).Demo:
Unpatched (built from 1e97a6d) <- This produces partial SVGs & unpredictable.
Patched <- This produces full SVG