async `load` function
An async function simply named load could be used to load any file or multiple files asynchronously and return a promise.
This will be implemented in q5-util.js The q5 setup function is already async.
This idea was suggested by @mattdesl and iterated on by @mvicky2592 in this p5.js issue discussion. I also think keeping the preload system for backwards compatibility and ease of use for beginners is the right idea though.
https://github.com/processing/p5.js/issues/6767
@DipakKhade Thanks for the PR! But please comment on an issue before trying to implement a feature though.
The implementation of load(...args) should use Promise.all. Also it should be able to load many types of files, not just text and json. It would need to be a function added to instances of Q5 not Q5 itself, in order to access other loading functions.
After examining the p5 feature request again more closely, I'm a bit confused myself about how they plan to support loading images, video, and sounds with this one method. I suppose it could wrap preload functions like loadImage and loadSound in a promise. What do you think of that idea?
I also think we need to figure out a way for addon developers to add support to q5 load for loading additional file types but that could be added after an initial implementation is done.
I had an idea on how to do this by having each preload function like loadSound make the returned object include a property storing a promise that resolves when it's loaded.
Whatever you decide, please, don't get rid of the classic loading functions like p5js is doing for its version 2! 🙏
@GoToLoop oh for sure I won't. That's crazy, are they actually committing to that?
Well, this already merged commit have all preload-related code removed! https://github.com/processing/p5.js/pull/7203
IMO, Processing flavors should strive to be more similar to the original Java Processing than trying to strictly adhere to the syntax of its target language.
Getting rid of callback loading syntax, and therefore completely breaking old code, just b/c JS pro devs prefer async + await syntax is totally unwise!
AFAIK, Processing's target public isn't professional programmers! And JS promise syntax is considered hard to learn!
I'm all in favor of including support for async/await syntax in JS Processing flavors, but not as a replacement of an easier to understand callback loading syntax!
implemented in v2.16