-
• #2
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: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
Hi,
I'm generating several csv files on the bangle.js. Once it's done, I would like to make a convenient tool to download all files at the same time. For that, I'm creating a html tool for the app loader.
I followed the existing examples and start with:
This works and finds all my files. Then, in the loop, I would like to find a way to download everything at once. A satisfying way would be to concatenate all strings in the variable csvData, and then save it into a unique csv file on my computer. But definitely the best solution would be to save all files individually by pushing one button.
But I couldn't make it work at all. I'm also very confused about how the code is executed. The code after the loop "forEach" always finish after the code bellow despite not using async.
Could you give me some direction on how to solve my issue?
Thanks!