the issue we have is if there is a failure - 0 is returned and we don't know which error occured or where...
However in debugging - I found a work around.
In the function - calling f=process.memory().free; seems to work. All I can think that is occuring here is it perhaps a garbage collection is occuring - @Gordon - any ideas?
var fs = require('fs');
function writeData(i){
// line below allows this to run!
f=process.memory().free;
//console.log(process.memory().free );
if(i < 40){
var data = Math.random().toString();
var name = `file_${i}`;
var res = fs.writeFile(name, data);
if(res){
console.log(`wrote... ${name}, ${data}`);
setTimeout(function(){
writeData(i + 1);
}, 100);
}
else{
console.log(`did not write!, ${name}, ${data}`);
}
}
}
writeData(0);
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.
Hi,
using your original code - I can replicate the issue - it stops after 15 iterations.
I suspected that memory was leaking so intially added a line to print free memory - as I suspected that this was the problem.
https://github.com/espruino/Espruino/blob/e06b3e24de42adb1de6e2cc6046e525880760e7d/libs/filesystem/jswrap_file.c#L277
the issue we have is if there is a failure - 0 is returned and we don't know which error occured or where...
However in debugging - I found a work around.
In the function - calling
f=process.memory().free;
seems to work. All I can think that is occuring here is it perhaps a garbage collection is occuring - @Gordon - any ideas?