Closed
Description
Most appropriate sub-area of p5.js?
- Accessibility
- Color
- Core/Environment/Rendering
- Data
- DOM
- Events
- Image
- IO
- Math
- Typography
- Utilities
- WebGL
- Build process
- Unit testing
- Internationalization
- Friendly errors
- Other (specify if possible)
p5.js version
2.0.0-beta.3
Web browser and version
Brave 1.75.178, Chrome 133.0.6943.142, Firefox 135.0
Operating system
Windows 10
Steps to reproduce this
Many of the p5.js load functions don't work correctly with await; they seem to return prematurely. I use loadStrings in the snippet below, but have seen the same problem in loadShader and loadBytes; it is probably an issue with others. In the code below, I use "await loadStrings" to load data from a text file, which should wait until the data is loaded to continue. But printing it immediately prints an empty array. The successCallback works fine; the correct data is printed in the callback function. (But the problem arises even if no callback function is given.)
Steps:
- Call await loadStrings (or loadShader or loadBytes) in the async setup function
- The await should make the function wait until the data is available, but the data is empty
Snippet:
https://editor.p5js.org/rsidwell/sketches/aVQd6eoOG
let myData;
async function setup() {
myData = await loadStrings('test.txt', gotData);
print(myData);
}
function gotData(d) {
myData = d;
print(myData);
}