TLDR: Use for...of instead of forEach() in asynchronous code.
For legacy browsers, use for(...;...;...) or [].reduce()
To execute the promises in parallel, use Promise.all([].map(...))
| // Type declarations for ExtendScript Built-in types | |
| // Initial declarations by: Eric Robinson <eric@sonicbloom.io> | |
| /** | |
| * The base class of all JavaScript objects. | |
| */ | |
| interface Object { | |
| /** | |
| * Points to the constructor function that created this object. | |
| * Note that this property is treated as an XML element in the XML class. |
| /* A quick reminder on how to use Promises with Node and Express in order to run potentially | |
| * time-consuming jobs asynchronously (assuming the jobs are able to run in the background thanks to | |
| * libuv and actually return Promises). | |
| * | |
| * Start the server, navigate to /startjob, then refresh a few times, the job should be in progress. | |
| * You can navigate elsewhere in the "app" in other browser tabs in the meanwhile (/). After about | |
| * 20s, you should get a result by refreshing the tab where you originally submitted the job. | |
| * | |
| * I hope this pattern will be useful e.g. for processing images with the `sharp` library (see | |
| * <http://sharp.dimens.io>). |