Skip to content

Commit 766fce0

Browse files
authored
Using loadImage and removing helper-function
1 parent 76bf50e commit 766fce0

File tree

1 file changed

+3
-12
lines changed
  • src/content/examples/en/16_Parallel_Loading_Promise/00_Async_Image_Loader

1 file changed

+3
-12
lines changed

src/content/examples/en/16_Parallel_Loading_Promise/00_Async_Image_Loader/code.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ async function setup() {
2020
// Use async/await with Promise.all to load all three images at once
2121
// This waits until ALL images are loaded before continuing
2222
[img1, img2, img3] = await Promise.all([
23-
loadImageAsync('https://picsum.photos/100/100?random=1'), // Replace the image links with user wanted images.
24-
loadImageAsync('https://picsum.photos/100/100?random=2'),
25-
loadImageAsync('https://picsum.photos/100/100?random=3')
23+
loadImage('https://picsum.photos/100/100?random=1'), // Replace the image links with user wanted images.
24+
loadImage('https://picsum.photos/100/100?random=2'),
25+
loadImage('https://picsum.photos/100/100?random=3')
2626
]);
2727

2828
// Once all images are ready, draw them on the canvas
@@ -35,12 +35,3 @@ async function setup() {
3535
text("All images loaded!", width / 2, 50);
3636
}
3737

38-
// Helper function to load images using a Promise
39-
// Makes loadImage compatible with async/await style
40-
function loadImageAsync(url) {
41-
return new Promise((resolve, reject) => {
42-
// Try to load the image from the given URL.
43-
//If successful, resolve the promise with the image. If it fails, reject with the error.
44-
loadImage(url, img => resolve(img), err => reject(err));
45-
});
46-
}

0 commit comments

Comments
 (0)