setTimeout

Posted on
  • Hello,

    I currently writing a module to support xbee modules in API mode. Once working/finished, i will contribute it.

    It uses mainly a lot of serial communcation, i.e the serial class. For timeout handling i use some setTimeout/clearTimeout functions. I do not use any Filesystem/SD card functions.

    From one time to another, i got a strange behavior. It took a while to find out what is wrong.

    The function SetTimeout calls the callback function immediately, regardless how i set the timeout parameter.

    After a physical reset of the module, everything is fine again. setTimeout is working again as excepted.

    Until now i was not able to reproduce it.

    Sacha

  • Maybe it can be reproduced.

    I had a javascript Error inside the Serial function onData. I got the following
    Error:

    ERROR: Using '.' operator on non-object at line 4 col 20

        for(i=0;i<a.length;i++) {
                    ^
    

    at line 7 col 9

        msg+="\nASC:";
         ^
    

    in function "debugHEX" called from line 5 col 39
    in function called from line 27 col 49
    in function "prepCB" called from line 29 col 59
    in function called from system
    ERROR: Error processing Serial data handler - removing it.
    Execution Interrupted during event processing.

    Maybe setTimeout() fails after an error inside onData.

    Sacha

  • Next time this fails, check what you're getting from getTime(). I've seen the timer switch from seconds to ms after sd card errors, maybe can be triggered other ways? When this happens, of course, timeouts and intervals get called way too fast.

  • I was not able to reproduce it, even with a "code error" inside Serial.onData. But i'm prepaired.

  • I think this could be the same issue DrAzzy is having... After a while (it's more or less random), the time from getTime starts increasing wildly. I'm looking at this though and hopefully a fix will come out in 1v59.

  • I left the Espruino over night connected. Just waiting that something happens on the Serial connection (Serial1.onData callback registered). No data received but the timing is way off.

    The following statement took 3-4 Seconds only:

    console.log("Start-Time: "+getTime()); setTimeout(function() { console.log("After a very long wait.: "+getTime()); }, 10000000);

    Start-Time: 49936143.57320594787597
    =1
    After a very long wait.: 49946147.45812225341796

  • I believe this is fixed now in the 'nightly' compiles (I fixed it yesterday). I might try and push 1v59 out today, or you can use the binary from:

    http://www.espruino.com/binaries/git/com­mits/e85fa5a013c3a1469635b92e12a35591eb2­589d8

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

setTimeout

Posted by Avatar for Sacha @Sacha

Actions