• As I understand it, Espruino internally keeps an event queue, so when timeout or interval timers fire, the appropriate task is added to the queue, and handled in order when the interpreter is next idle.

    So, let us consider a program where we have an interval set to run every 20 milliseconds:

    setInterval("animateLEDs()",20);

    Now, let's say we're also connected to the interwebs, and it has to make an HTTP request from, say, coldmolasses.net , which takes 10 seconds to reply, during which time (as I understand it) everything blocks. Whether HTTP requests still block is immaterial here though - point is, a task that blocks for significantly longer than the 20 millisecond interval.

    What happens to that interval during that time?

    I vaguely recall that this would result in a whole bunch of callbacks on the interval getting queued up.
    Am I correct so far?

    While in some cases this is a good thing, I might not want that.

    So I might do:

    
    setTimeout("onTimeout()",20);
    function onTimeout() {
    animateLEDs();
    setTimeout("onTimeout()",20);
    }
    
    
    

    Am I on the right track here?
    Is my understanding of interval/timeout and the event queue correct, or has my time working with Arduino clouded my brain? (it's such a shock going between "don't approach a String without stakes, holy water and a clove of garlic" and "Strings are fast and efficient, use them whenever you want to")

    Is there a part of the reference that describes how the queue'ed events work (basically, this stuff, and how events from setWatch get queued up)

About

Avatar for DrAzzy @DrAzzy started