Skip to content

Commit a778cf1

Browse files
authored
Update README.md
1 parent fdaee7f commit a778cf1

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,11 @@ async function setup() {
9595

9696
If it takes a while to load the image, the sketch will be "paused" on the line `img = await loadImage('/assets/bricks.jpg');` - once the image is loaded, it will resume.
9797

98+
9899
## …using registerPreloadMethod in a addon or library
99100

101+
Under to hood, returns a **Promise** from each loadImage, loadSound, and similar functions. Promises are widely used in JavaScript, so it is possible to use a callback in p5.js 1.x to create a Promise, but p5.js 1.x doesn't expect promises to be used, so you have to ensure yourself that, for example, your draw function doesn't start running before loading is done. For an example of a Promise using a call back, check out the example below that makes p5.sound.js compatible with both 1.x and 2.0:
102+
100103
If your addon built with p5.js 1.x uses `registerPreloadMethod` such as in this example from [p5.sound.js](https://github.com/processing/p5.sound.js):
101104

102105
```js

0 commit comments

Comments
 (0)