Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we add Reset functionality as well? #4

Open
shreyasshivashankar opened this issue Dec 7, 2020 · 2 comments
Open

Can we add Reset functionality as well? #4

shreyasshivashankar opened this issue Dec 7, 2020 · 2 comments

Comments

@shreyasshivashankar
Copy link

No description provided.

@shalithasuranga
Copy link
Contributor

Hey.. you mean pause/start option? I think .stop() can be used to reset

@shreyasshivashankar
Copy link
Author

int a = 0;
int resetTimer(Timer &timer) {
timer.stop();
cout << "Timer reset" << endl;
timer.setTimeout(& {
std:cout << a <<std::endl;
a++;
}, 5000);
return 1;
}

int main() {
Timer t = Timer();
resetTimer(t);
while (true) {
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
resetTimer(t);
}
// while(true); // Keep main thread active
}
####### Output #######
Timer reset
0
Timer reset
1
Timer reset
2
Timer reset
3
Timer reset
4
Timer reset
5

If its actually resetting, "a" should never be output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants