chore: Add course material
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
// ======================================================
|
||||
// timer.cpp
|
||||
// ======================================================
|
||||
|
||||
#include "Timer.h"
|
||||
#include "TimerSet.h"
|
||||
|
||||
void Timer::timeoutRequest(int seconds) { timeToGo = seconds; }
|
||||
|
||||
Timer::Timer(std::function<void(void)> action) : timeToGo(-1), doExpired(action) {
|
||||
TimerSet::Instance().addATimer(this);
|
||||
}
|
||||
|
||||
void Timer::tick() {
|
||||
if (isExpired()) {
|
||||
doExpired();
|
||||
}
|
||||
}
|
||||
|
||||
bool Timer::isExpired() {
|
||||
if (timeToGo > 0) {
|
||||
if (--timeToGo == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user