Skip to content

setInterval() Bug #1

@Hannes-III

Description

@Hannes-III

over night I have been thinking about that.
We implemented the fix it by placing: if (iEnabled) enable(); into Task::setIterations().
I am not sure if that is completely right and if it should not be like:

void Task::setIterations(long aIterations) { 
    if (iEnabled && iIterations == 0) enable();
    iSetIterations = iIterations = aIterations; 
}

You have to decide if that makes sense . My motivation was:

  1. if iterations is not 0 there was no problem, so there was no need to do it.
  2. but more importantly: enable() resets the iPreviousMillis value. But in the case, that the Task is still running, this would destroy the current interval.
    I have a Task running. Its Interval is set to 1o.ooo ms. Every 1o seconds the callback is run.
    Four seconds after the callback was run, I call Task::setIterations() this will reset the Value of iPreviousMillis in a way that the task is due to run immediately. But it should wait another six seconds.

I placed it before the reset of the Variables so that I have the untouched iIterations to compare. I think that is OK too.

You wrote that you have placed the fix into Task::set() too. I Think that was not necessary, before I knew what the Problem was and before there was Task::restart() I used full Task::set() as workaround for Task::setIterations(), because there it worked without any Problems. Although now, looking at the code I cannot understand why.

PS.: great Library, Thank You.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions