Skip to content

Adding documentation Example on how to do parallel loading with Promi… #825

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

Open
wants to merge 13 commits into
base: 2.0
Choose a base branch
from

Conversation

Mamatha1718
Copy link

@Mamatha1718 Mamatha1718 commented Apr 29, 2025

Added New Example: Parallel Loading with Promise.all

Adding a new example demonstrating how to use Promise.all with asynchronous functions in p5.js.

Solve Issue #7674

JavaScript File (.js):

Implements Promise.all to load multiple assets in parallel and display the result after all are resolved.

Description File (.mdx):

Explains the concept of Promise.all.

Thumbnail image:

16_Async_Await_PromiseAll-thumbnail.png added to src/content/examples/images/featured/.

@ksen0 ksen0 changed the base branch from main to 2.0 May 13, 2025 11:39
@ksen0 ksen0 changed the base branch from 2.0 to main May 13, 2025 11:39
@ksen0
Copy link
Member

ksen0 commented May 13, 2025

Hi @Mamatha1718 thank you for putting this together! Because this example is for the 2.0 version and the beta site, please file this PR against the 2.0 branch. (You'll have to checkout 2.0, make new branch, and add your files there.) Thanks so much for the nice work here. I've also left a couple minor comments.

Additionally, please place the .mdx file under en/03_Imported_Media rather than creating a separate directory

cc @perminder-17 - assigning you as reviewer, please feel free to ask for revisions / merge when you feel it's ready.

Thanks all!

@ksen0 ksen0 requested a review from perminder-17 May 13, 2025 11:41
// Use async/await with Promise.all to load all three images at once
// This waits untill ALL images are loaded before continuing
[img1, img2, img3] = await Promise.all([
loadImageAsync('https://picsum.photos/100/100?random=1'), // Replace the image links with user wanted images.
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the detailed documentation here! Could you explain the logic a bit more behind the helper loadImageAsync please? I tried the example and loadImage here works just as well, and the helper function does not actually have any other params - if you had another idea with this, please let me know, but if it's ok with you, I'd suggest the shorter example with only loadImage here.

textSize(18);

// Use async/await with Promise.all to load all three images at once
// This waits untill ALL images are loaded before continuing
Copy link
Member

Choose a reason for hiding this comment

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

Minor/spelling: "untill" -> "until"

@perminder-17 perminder-17 changed the base branch from main to 2.0 May 15, 2025 21:08
@perminder-17 perminder-17 changed the base branch from 2.0 to main May 15, 2025 21:09
@perminder-17 perminder-17 changed the base branch from main to 2.0 May 15, 2025 21:15
Copy link
Collaborator

@perminder-17 perminder-17 left a comment

Choose a reason for hiding this comment

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

Hi @Mamatha1718 , Really thanks for working on this. Your contributions really matters and are really appreciated. Just requesting a minor changes, as @ksen0 said:

Could you please retarget your PR to the 2.0 branch and re-base your work on top of it?

Steps:

  1. In the PR, click Edit ➜ change the base from main to 2.0 ➜ Save (Already I did)

Locally:

git fetch origin
git checkout example
git rebase origin/2.0
git push --force-with-lease

This will make the PR show only your intended changes against 2.0, with conflicts resolved. Thanks!

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.

5 participants