#include <arduino-timer.h>

Timer<10> MainTimer; // Timer with 10 task slots
Timer<>::Task DummyTask; // A task of the timer
unsigned int Counter = 0;

void setup() {

  Serial.begin(9600);
  Serial.println("Program started - Wrong Handling of Timer ID");
  Serial.println("----------------------------------------------");
  Serial.println("After 5 seconds, the DummyTask will be canceled from the inside");
  Serial.println("(by returning 'false'), but DummyTask will still have its original ID");
  Serial.println();

  /* Let's output Serial information every 2 seconds */
  MainTimer.every(1000, SerialPrinter);

  /* Set a dummy task */
  DummyTask = MainTimer.every(1000, DummyFunction);
}

void loop() {
  // put your main code here, to run repeatedly:
  MainTimer.tick<void>(); // avoids ticks() calculation
}

bool SerialPrinter(void *) {
    Serial.print("Timers: ");
    Serial.print(MainTimer.size());
    Serial.print(" | Dummy Task ID: ");
    Serial.print(DummyTask);

    Serial.println();

    return true;
}

bool DummyFunction(void *) {

    /* 
      After 5 seconds, we cancel the timer by returning false
      Canceling the timer using this method, makes the DummyTask retain its original ID,
      while it should be 0 !
    */
    if(++Counter == 5) {
      return false;
    }

  return true;
}