28 lines
484 B
Vala
28 lines
484 B
Vala
namespace StudySystemClient {
|
|
public abstract class Periodic {
|
|
private uint period_ms;
|
|
private bool exit;
|
|
private Thread<void> thread;
|
|
|
|
protected Periodic(uint period_ms) {
|
|
this.period_ms = period_ms;
|
|
exit = false;
|
|
thread = new Thread<void>("Periodic task", body);
|
|
}
|
|
|
|
~Periodic() {
|
|
exit = true;
|
|
thread.join();
|
|
}
|
|
|
|
protected abstract void task();
|
|
|
|
private void body() {
|
|
while (!exit) {
|
|
task();
|
|
Thread.usleep(1000 * period_ms);
|
|
}
|
|
}
|
|
}
|
|
}
|