Skip to content

Commit 302bcb9

Browse files
committed
Merge branch 'mc/cancel-all'
* mc/cancel-all: README: document cancel all usage of cancel() src:arduino-timer: cancel all version of cancel()
2 parents 9f6f82b + 3b33580 commit 302bcb9

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ auto task = timer.in(delay, function_to_call);
5656
timer.cancel(task);
5757
```
5858

59+
To **cancel** all *Task*s
60+
```cpp
61+
timer.cancel();
62+
```
63+
5964
Be fancy with **lambdas**
6065
```cpp
6166
timer.in(1000, [](void*) -> bool { return false; });
@@ -116,6 +121,8 @@ every(unsigned long interval, handler_t handler, T opaque = T());
116121

117122
/* Cancel a timer task */
118123
void cancel(Timer<>::Task &task);
124+
/* Cancel all tasks */
125+
void cancel();
119126

120127
/* Returns the ticks until next event, or 0 if none */
121128
unsigned long ticks();

src/arduino-timer.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@ class Timer {
9696
task = (Task)NULL;
9797
}
9898

99+
/* Cancel all timer tasks */
100+
void
101+
cancel()
102+
{
103+
for (size_t i = 0; i < max_tasks; ++i) {
104+
struct task * const t = &tasks[i];
105+
remove(t);
106+
}
107+
}
108+
99109
/* Ticks the timer forward - call this function in loop() */
100110
unsigned long
101111
tick()

0 commit comments

Comments
 (0)