• 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/b­lob/c99e4e53a8cb73220cbcd2f1950aafcbda89­a268/apps/accelrec/interface.html#L38

    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

About

Avatar for Gordon @Gordon started