Basically you want to make sure you execute everything one after the other, so create a promise with var promise = Promise.resolve(); (which you have done) and then in the forEach function do:
promise = promise.then(function() {
return new Promise(resolve=>{
// do stuff in here, call resolve() when ready
});
});
Finally you can call promise.then(function() { .... }) again to have that code run when all files are read
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
The issue is that while you may not be using async stuff yourself, Puck.eval is async behind the scenes.
I think the code you're after is actually already created as part of
accelrec
which has almost identical code to yours anyway: https://github.com/espruino/BangleApps/blob/c99e4e53a8cb73220cbcd2f1950aafcbda89a268/apps/accelrec/interface.html#L38Basically you want to make sure you execute everything one after the other, so create a promise with
var promise = Promise.resolve();
(which you have done) and then in theforEach
function do:Finally you can call
promise.then(function() { .... })
again to have that code run when all files are read