-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkSystem2.js
57 lines (54 loc) · 1.52 KB
/
checkSystem2.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
57
const os=require('os');
const RX=require('rxjs/RX');
const promiseMemCheck=new Promise((resolve,reject)=>{
const memSize=os.totalmem();
if(memSize<4*1024*1024*1024)
reject("Memory not sufficient");
else
resolve("Memory ok");
});
const promiseCpuCheck=new Promise((resolve,reject)=>{
const cpuCores=os.cpus().length;
if(cpuCores<2)
reject("Processor not supported");
else
resolve("Cpu ok");
});
function checkSystem()
{
console.log("Checking system ...");
Promise.all([promiseMemCheck,promiseCpuCheck]).then((values)=>console.log("System successfully checked")).catch(
(errors)=>console.error(errors));
}
function checkSystemNestedPromises()
{
console.log("Checking system ...");
promiseMemCheck.then(promiseCpuCheck).then((values)=>console.log("System successfully checked")).catch(
(errors)=>console.error(errors));
}
function checkSystemObservable()
{
console.log("Checking system ...");
RX.Observable.create(observer=>{
const memSize=os.totalmem();
if(memSize<4*1024*1024*1024)
{
observer.error("Memory not sufficient");
observer.complete();
}
const cpuCores=os.cpus().length;
if(cpuCores<2)
{
observer.error("Processor not supported");
observer.complete();
}
observer.next("System successfully checked");
observer.complete();
}).subscribe(
(message)=>console.log(message),
(err)=>console.log(err)
)
}
checkSystem();
checkSystemNestedPromises();
checkSystemObservable();