• 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/blo­b/e06b3e24de42adb1de6e2cc6046e525880760e­7d/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?

    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);
    
    WARNING: gap set scan error code = 103
    WARNING: set rssi scan not implemeted yet
    wrote... file_0, 0.67312209572
    wrote... file_1, 0.85650798066
    wrote... file_2, 0.11667447496
    wrote... file_3, 0.98353582061
    wrote... file_4, 0.55870476251
    wrote... file_5, 0.06997160197
    wrote... file_6, 0.05838990447
    wrote... file_7, 0.31009601164
    wrote... file_8, 0.35821451589
    wrote... file_9, 0.24528766667
    wrote... file_10, 0.51275360515
    wrote... file_11, 0.04978711532
    wrote... file_12, 0.76238244714
    wrote... file_13, 0.11774935718
    wrote... file_14, 0.99340898217
    wrote... file_15, 0.39304630709
    wrote... file_16, 0.48263351408
    wrote... file_17, 0.02755051107
    wrote... file_18, 0.68166789304
    wrote... file_19, 0.64597696841
    wrote... file_20, 0.14027355012
    wrote... file_21, 0.73948647814
    wrote... file_22, 0.17078908633
    wrote... file_23, 0.49875334300
    wrote... file_24, 0.60857436741
    wrote... file_25, 0.09730707253
    wrote... file_26, 0.89388832072
    wrote... file_27, 0.05864839910
    wrote... file_28, 0.26445292693
    wrote... file_29, 0.35654671180
    wrote... file_30, 0.41393465335
    wrote... file_31, 0.37957622081
    wrote... file_32, 0.37698324787
    wrote... file_33, 0.14988256066
    wrote... file_34, 0.04350866705
    wrote... file_35, 0.31650148859
    wrote... file_36, 0.23993254836
    wrote... file_37, 0.81480026189
    wrote... file_38, 0.59223879482
    wrote... file_39, 0.37215752032
    > 
    
About

Avatar for Wilberforce @Wilberforce started