forked from bright-systems/react-native-device-log
-
Notifications
You must be signed in to change notification settings - Fork 1
/
timers.js
39 lines (33 loc) · 783 Bytes
/
timers.js
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
const timestamp = {
now: () => {
return new Date().getTime();
},
};
export class Timers {
constructor() {
this.timers = {};
}
start(timer_name) {
this.timers[timer_name] = {
start: timestamp.now(),
stop: undefined,
delta: undefined,
};
return this.timers[timer_name];
}
stop(timer_name) {
const timer = this.timers[timer_name];
timer.stop = timestamp.now();
timer.delta = timer.stop - timer.start;
return timer;
}
get(timer_name) {
return this.timers[timer_name];
}
remove(timer_name) {
if (this.timers[timer_name]) {
delete this.timers[timer_name];
}
}
}
export default new Timers();