-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdemo.js
43 lines (37 loc) · 877 Bytes
/
demo.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
var monitor = require('./'),
loopDone = false,
afterTicks = 0,
loopCount = 0;
setInterval(function dummy(){
// just to keep prcess running
}, 100);
function loop() {
console.log('Starting heavy loop #%d', loopCount);
var s = +new Date();
while (true) {
if (+new Date() - s > 5000) {
console.log('Heavy loop #%d is done', loopCount);
loopCount++;
if (loopCount < 5) {
setImmediate(loop);
} else {
loopDone = true;
}
break;
}
}
}
monitor.on('data', function(latencyData) {
console.log(JSON.stringify(latencyData, null, 2));
if (loopDone) {
afterTicks++;
if (afterTicks > 3) {
process.exit();
}
}
});
monitor.resume();
console.log('Waiting 10 sec and starting a 5 heavy loops');
setTimeout(function(){
loop();
}, 10000);