Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: promise-based chunked rendering #3484

Merged
merged 3 commits into from
Jan 11, 2024
Merged

Refactor: promise-based chunked rendering #3484

merged 3 commits into from
Jan 11, 2024

Conversation

katspaugh
Copy link
Owner

@katspaugh katspaugh commented Jan 11, 2024

Short description

As outlined in a comment in #3480, I've refactored the code that was awaiting all waveform chunks to be rendered into sequenced promises.

Implementation details

The rendering timeouts are now also promise-based, and it a render timeout is cancelled due to another rendering (e.g. when zooming using a slider), it will also reject the correspondng promise. So it's possible to track the entire chain of promises to determine where rendercomplete should be called.

@brian-byassee @jason-whitted please review

Copy link
Contributor

github-actions bot commented Jan 11, 2024

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 2 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action

Copy link

cloudflare-workers-and-pages bot commented Jan 11, 2024

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 13b0b15
Status: ✅  Deploy successful!
Preview URL: https://159db3a5.wavesurfer-js.pages.dev
Branch Preview URL: https://promises.wavesurfer-js.pages.dev

View logs

src/renderer.ts Outdated
Comment on lines 602 to 607
await Promise.allSettled(
Array.from({ length: audioData.numberOfChannels }).map((_, i) => {
const options = { ...this.options, ...this.options.splitChannels?.[i] }
return this.renderChannel([audioData.getChannelData(i)], options, width)
}),
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allSettled will prevent the catch from being invoked in subsequent renders.

This seems like more render calls would be happing than one might expect.

I think Promise.all might be the better option here. But I may be miss understanding something here.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, thank you, we want to reject the entire promise when one of them fail.

@katspaugh katspaugh merged commit e59ac35 into main Jan 11, 2024
4 checks passed
@katspaugh katspaugh deleted the promises branch January 11, 2024 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants