Skip to content

2.5.0

Latest

Choose a tag to compare

@Aasim-A Aasim-A released this 26 Oct 02:13
2.5.0
6d56938

New feature

setInterval() callbacks can now receive their own unsigned short ID, making self-cancellation possible without capturing an ID variable before it is initialized. Fixes #23.

With a global AsyncTimer t, register this inside setup():

unsigned int remaining = 5;
t.setInterval([remaining](unsigned short id) mutable {
  Serial.println("Tick");
  if (--remaining == 0) {
    t.cancel(id);
    return;
  }
}, 1000);

Existing zero-argument interval callbacks continue to work. setTimeout() callbacks remain zero-argument. See the new CancelIntervalFromCallback example for a complete sketch.

Fixes

  • Timers continue working across millis() rollover, including getRemaining(), postponement, and reset. Fixes #26.
  • cancelAll() safely handles empty or partially used timer arrays and repeated cancellation.
  • Timer IDs remain nonzero and unique among active timers, including after ID wraparound.
  • Running callbacks remain alive when they cancel themselves or schedule replacements; completed and cancelled callbacks release their captures.

Tests

Added 103 PC-only test cases covering the public API, rollover, callback lifetime, self-cancellation, and all six example sketches. The suite also checks 75,000 deterministic operations against a reference model. No Arduino hardware or SDK is required.

CI passes on Linux, macOS, Windows, Linux 32-bit, and with address/undefined-behavior sanitizers. See tests/README.md for instructions.

Full changelog: 2.4.1...2.5.0