• what about counting 10 calls inside handler with help of global variable and doing NRF.setRSSIHandler(); only after that?

    Javascript/espruino is single threaded and event based so until your code ends nothing else runs.
    The exception are hardware interrupts and bluetooth stack is also based on those so the rssi handler may be still called in your code despite your busy loop (not sure) but your code resets it very quickly anyway so it has no chance to run 10 times exactly.

    BTW what is wait(5000); ? There is no such thing in Espruino and it goes against basic principle of javascript

    I'd use setInterval with 5 second delay, set the RSSI handler there every 5 seconds and then do as suggested in first line - unset handler after 10 calls are made

  • wait is a function that I added:

    function wait(ms){
    var start = new Date().getTime();
    var end = start;
    while(end < start + ms) {

    end = new Date().getTime();
    

    }
    }

    even after giving the loop inside the variable creates issue as I am running an infinite while loop. And for that, JS is first trying to finish the infinite loop ( which is not happening) keeping the calling of the handler in queue.

    Does Espruino supports async/ await? This would have easily solved the issue. Or is there any way to restart the whole code after every complete run?

About

Avatar for fanoush @fanoush started