-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
sample.js
48 lines (37 loc) · 1.37 KB
/
sample.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
const startCpu = process.cpuUsage();
const os = require("os");
const saveLocal = require(".");
const AssetCache = saveLocal.AssetCache;
(async () => {
saveLocal.concurrency = 2;
let options = {
duration: "4h",
};
let promises = [];
// don’t await here to test concurrency
let first = saveLocal("https://www.zachleat.com/img/avatar-2017-big.png", options);
promises.push(first);
promises.push(saveLocal("https://github.com/11ty/eleventy/releases.atom", {
type: "text"
}));
// let second = saveLocal("https://www.zachleat.com/img/avatar-2017-big.png", options);
// promises.push(second);
// promises.push(saveLocal("https://www.zachleat.com/web/css/fonts/lato/2.0/LatoLatin-Regular.ttf", options));
// let json = saveLocal("https://opencollective.com/11ty/members/all.json", {
// duration: options.duration,
// type: "json"
// });
// promises.push(json);
let asset = new AssetCache("twitter-followers-eleven_ty");
if (asset.isCacheValid("4d")) {
console.log(await asset.getCachedValue());
} else {
asset.save({ followers: 42 }, "json");
}
await Promise.all(promises);
// console.log( JSON.stringify(await json).substr(0, 100), "… (truncated)" );
console.log(process.cpuUsage(startCpu));
console.log(os.freemem() / (1024 * 1024), os.totalmem() / (1024 * 1024));
// console.log( process.memoryUsage() );
// console.log( process.resourceUsage() );
})();