-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtimeout.vala
44 lines (36 loc) · 918 Bytes
/
timeout.vala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* vim: set cin et sw=4 : */
public class Timeout {
public delegate void Func();
uint source;
uint interval;
unowned Func f;
static Gee.ArrayList<weak Timeout> all = new Gee.ArrayList<weak Timeout>();
public Timeout(uint interval, Func f) {
source = 0;
this.interval = interval;
this.f = f;
all.add(this);
}
~Timeout() {
all.remove(this);
}
public void reset() {
if (source > 0)
GLib.Source.remove(source);
source = GLib.Timeout.add_seconds(interval, () => {
source = 0;
f();
return false;
});
}
public void trigger() {
if (source > 0) {
GLib.Source.remove(source);
f();
}
}
public static void trigger_all() {
foreach (var timeout in all)
timeout.trigger();
}
}