Comparing version 2.0.18 to 2.0.19
@@ -42,2 +42,3 @@ 'use strict' | ||
interval = setInterval(runInvalidator, (maxage || DEFAULT_MAXAGE) / 2) | ||
interval.unref() | ||
} | ||
@@ -44,0 +45,0 @@ |
{ | ||
"name": "pidusage", | ||
"version": "2.0.18", | ||
"version": "2.0.19", | ||
"description": "Cross-platform process cpu % and memory usage of a PID", | ||
@@ -34,10 +34,10 @@ "license": "MIT", | ||
"devDependencies": { | ||
"ava": "^2.4.0", | ||
"ava": "^3.8.2", | ||
"codecov": "^3.0.2", | ||
"mockdate": "^2.0.2", | ||
"mockdate": "^2.0.5", | ||
"mockery": "^2.1.0", | ||
"nyc": "^13.0.0", | ||
"nyc": "^15.0.1", | ||
"pify": "^3.0.0", | ||
"standard": "^14.3.1", | ||
"string-to-stream": "^1.1.0", | ||
"standard": "^14.3.4", | ||
"string-to-stream": "^1.1.1", | ||
"through": "^2.3.8", | ||
@@ -44,0 +44,0 @@ "time-span": "^2.0.0" |
@@ -23,4 +23,4 @@ # pidusage | ||
// Compute statistics every second: | ||
setInterval(function () { | ||
// Avoid using setInterval as they could overlap with asynchronous processing | ||
function compute(cb) { | ||
pidusage(process.pid, function (err, stats) { | ||
@@ -37,5 +37,15 @@ console.log(stats) | ||
// } | ||
cb() | ||
}) | ||
}, 1000) | ||
} | ||
// Compute statistics every second: | ||
function interval(time) { | ||
setTimeout(function() { | ||
compute(function() { | ||
interval(time) | ||
}) | ||
}, time) | ||
} | ||
// It supports also multiple pids | ||
@@ -78,2 +88,16 @@ pidusage([727, 1234], function (err, stats) { | ||
// } | ||
// Above example using async/await | ||
const compute = async () => { | ||
const stats = await pidusage(process.pid) | ||
// do something | ||
} | ||
// Compute statistics every second: | ||
const interval = async (time) => { | ||
setTimeout(async () => { | ||
await compute() | ||
interval(time) | ||
}, time) | ||
} | ||
``` | ||
@@ -118,3 +142,3 @@ | ||
If needed this function can be used to clear the event loop. Indeed, we're registering an interval to free up the in-memory metrics. By calling this, it will clear this interval and all delete all in-memory data. | ||
If needed this function can be used to delete all in-memory metrics and clear the event loop. This is not necessary before exiting as the interval we're registring does not hold up the event loop. | ||
@@ -121,0 +145,0 @@ ## Related |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31534
663
166