-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·56 lines (46 loc) · 1.35 KB
/
index.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env node
const si = require("systeminformation");
const mri = require("mri");
const sll = require("single-line-log").stdout;
const kleur = require("kleur");
const fork = require("child_process").fork;
const sleep = require("sleep");
async function readTemp() {
const temp = await si.cpuTemperature();
return { main: temp.main, cores: temp.cores };
}
function avg(arr) {
return arr.reduce((sum, t) => t.main + sum, 0) / arr.length;
}
async function runRestaurant(targetTemp) {
let temp = await readTemp(),
temps = [temp, temp, temp],
children = [];
while (1) {
if (avg(temps) < targetTemp) {
if (children.length < 40) {
children.push(fork("./cook-dish"));
}
} else if (avg(temps) > targetTemp) {
if (children.length > 0) {
children.pop().kill();
}
}
temp = await readTemp();
temps.shift();
temps.push(temp);
sll(
"Current oven temperature",
kleur.bold.red(temp.main.toFixed(2))
);
sleep.msleep(500);
}
}
const args = process.argv.slice(2),
targetTemp = mri(args, {
alias: { temp: "t" },
default: { temp: 85 }
});
console.log(kleur.bold.red('Chef\'s table')),
console.log('A necessary evil')
runRestaurant(targetTemp.temp);