Issue with leOS2 for one-time tasks I'm trying to use the last version of leOS2 scheduler from Leonardo Miliani ( https://github.com/leomil72/leOS2 ) but I have a strange behavior with a very simplistic ONETIME task.

Platform : Arduino Uno clone, so Atmel Atmega 328P CPU.

My code is very straightforward : 

#include "leOS2.h"
leOS2 myOS; //create a new istance of the class leOS

bool test = true;

void setup()
{
    myOS.begin(); //initialize the scheduler
}
void loop()
{
    // Do some stuff ...

    if(test)
    {
       DoAndUndo(3000);
       test = false;
    }
}

void DoAndUndo(unsigned long duration)
{
    doSomething();

    myOS.addTask(cancelTheThing, myOS.convertMs(duration), ONETIME);
}


void doSomething()
{
    Serial.println("thing on");
}

void cancelTheThing()
{
    Serial.println("thing is off");
}


In case it can be some kind of conflict, my code also relies on the following : 

#include &lt;Wire.h&gt;
#include &lt;LiquidCrystal_I2C.h&gt;
#include &lt;IRremote.h&gt;


The problem is :
        myOS.addTask(cancelTheThing, myOS.convertMs(duration), ONETIME);
is supposed to call asynchronously the "cancelTheThing" method 3 seconds later, and for only one time, and then forget it.
But for an unknown reason, it's called after the expected delay, but it loops infinitely on this method ! In the example case above, my serial stream is filled with a lot of "thing is off" messages, and the µc is unresponsive to anything apart a reset.

The call to DoAndUndo() will produce a such like output : 

 thing on


And 3s later, in a very fast infinite loop :

 thing is off
 thing is off
 thing is off
 thing is off


If I remove the "ONETIME" flag, the task is called every three seconds (exactly as it's suppose to do, so the scheduler works, but it's not what I want in my use case).

note : As a try of workaround, I've tried some tricks like calling haltScheduler() inside my cancelTheThing() and reenable it with restartScheduler() in DoAndUndo(), and also tried to call removeTask once it has ran, but it didn't help.

Thank you for your help
There appears to be a fault with the library whereby if the only registered task is a one-shot task it doesn't get cancelled when it has executed.

Adding another periodic task in setup() (say to blink an LED every 500ms) so there are now 2 tasks instead of one works around the problem.

The way the system is written it will always try an execute task number 0 even when there are 0 tasks registered because they erroneously used a "do {...} while" construct instead of a "while { ...}" construct.



I  have filed a bug report, corrected the error, and raised a pull request with the fix in it.  Until it gets accepted you can obtain the fixed version here: https://github.com/majenkotech/leOS2