Skip to content

Commit e1d912b

Browse files
committed
Add empty lines for readability
1 parent 3c07f2e commit e1d912b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

JavaScript/4-scheduler.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,21 @@ class Logger {
66
static color(level) {
77
return Logger.COLORS[level] || Logger.COLORS.info;
88
}
9+
910
log(level, s) {
1011
const date = new Date().toISOString();
1112
const color = Logger.color(level);
1213
console.log(color + date + '\t' + s + '\x1b[0m');
1314
}
15+
1416
warn(s) {
1517
this.log('warn', s);
1618
}
19+
1720
error(s) {
1821
this.log('error', s);
1922
}
23+
2024
info(s) {
2125
this.log('info', s);
2226
}
@@ -46,9 +50,11 @@ class Task extends EventEmitter {
4650
this.count = 0;
4751
this.timer = null;
4852
}
53+
4954
get active() {
5055
return !!this.timer;
5156
}
57+
5258
start() {
5359
this.stop();
5460
if (this.running) return false;
@@ -59,12 +65,14 @@ class Task extends EventEmitter {
5965
}, time);
6066
return true;
6167
}
68+
6269
stop() {
6370
if (!this.active || this.running) return false;
6471
this.clear(this.timer);
6572
this.timer = null;
6673
return true;
6774
}
75+
6876
run() {
6977
if (!this.active || this.running) return false;
7078
this.running = true;
@@ -85,6 +93,7 @@ class Scheduler extends EventEmitter {
8593
this.tasks = new Map();
8694
this.logger = new Logger();
8795
}
96+
8897
task(name, time, exec) {
8998
this.stop(name);
9099
const task = new Task(name, time, exec);
@@ -102,13 +111,15 @@ class Scheduler extends EventEmitter {
102111
task.start();
103112
return task;
104113
}
114+
105115
stop(name) {
106116
const task = this.tasks.get(name);
107117
if (task) {
108118
task.stop();
109119
this.tasks.delete(name);
110120
}
111121
}
122+
112123
stopAll() {
113124
for (const name of this.tasks.keys()) {
114125
this.stop(name);

0 commit comments

Comments
 (0)