arkhipenko/TaskScheduler

enableDelayed() calls Callback immediately

moritz89 opened this issue · 2 comments

This might be a communication issue regarding the documentation and function naming, but when creating a task and the calling enableDelayed(wait_time_ms) in the constructor, the Callback is called immediately after without respecting the delay. There seems to be no difference between enableDelayed() and enable() when used in the class interface.

A work-around is to manually handle the first iteration by saving the initial delay to a class member and then in the callback handling the first iteration manually:

MyTask::MyTask() {
  if(some_bool) {
    initial_delay_ = WAIT_CONTSTANT_MS;
  }
  enable();
}

bool MyTask::Callback() {
  if (isFirstIteration() && initial_delay_) {
    Task::delay(initial_delay_);
    return true;
  }
  ...
}

Might this not be a problem if using this approach: #78 (comment)

After further research it is probably due to user code 😅 but it does not seem trivial...

It was trivial, was calling enable() after the task was created/constructor called... sorry for the commotion. Lesson: sleep on it and debug the next day