mirror of https://github.com/eeeneko/ovo.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
漪綿 清烛
c21bd2491c
|
5 years ago | |
---|---|---|
.. | ||
README.md | 5 years ago |
README.md
Class Timer
To use this class, you need to put
#define _pthread
before your#include "ovo.h"
And also, useg++ yourCode.cpp -std=c++14 -pthread
to compile
Timer.setTimeout()
This can let your function be executed after certain time.
Params:
- auto function Your function.
Lambda Expression is allowed!
- int delay Time to delay in milliseconds.
Example
#include <iostream>
#define _pthread
#include "ovo.h"
using namespace std;
void display(){
cout << "Hey.. After 1s." << endl;
}
int main()
{
ovo::Timer t = ovo::Timer();
t.setTimeout(display, 1000);
while (1); //Keep the main thread never stop
return 0;
}
This will get the following result. (Use Ctrl+C to interrupt)
Hey.. After 1s.
Timer.setInterval()
This can let your function be executed repetitively with certain time.
Params:
- auto function Your function.
Lambda Expression is allowed!
- int delay Time for every interval in milliseconds.
Example
#include <iostream>
#define _pthread
#include "ovo.h"
using namespace std;
void display(){
cout << "Hey.. " << endl;
}
int main()
{
ovo::Timer t = ovo::Timer();
t.setInterval(display, 1000);
while (1); //Keep the main thread never stop
return 0;
}
This will get the following result. (Use Ctrl+C to interrupt)
Hey..
Hey..
Hey..
.
.
.
Timer.stop()
This can be used to stop a Timer.
Example
#include <iostream>
#define _pthread
#include "ovo.h"
using namespace std;
void display(){
cout << "Hey.. " << endl;
}
int main()
{
ovo::Timer t = ovo::Timer();
t.setInterval(display, 1000);
t.setTimeout([&]() {
cout << "Hey.. After 5.6s. I will stop the timer!" << endl;
t.stop();
}, 5600);
while (1); //Keep the main thread never stop
return 0;
}
This will get the following result. (Use Ctrl+C to interrupt)
Hey..
Hey..
Hey..
Hey..
Hey..
Hey.. After 5.6s. I will stop the timer