Browse Source

Merge pull request #219 from meriadec/master

Prevent blocking main process when fetching cpu infos
master
Loëck Vézien 7 years ago
committed by GitHub
parent
commit
7bb979f93e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      src/helpers/cpuUsage.js

10
src/helpers/cpuUsage.js

@ -1,9 +1,9 @@
const TIMEOUT_CPU_USAGE = 5e3
const cpuUsage = (startTime, startUsage) => {
const now = Date.now()
const wait = ms => new Promise(resolve => setTimeout(resolve, ms))
while (Date.now() - now < 500);
const cpuUsage = async (startTime, startUsage) => {
await wait(500)
const newStartTime = process.hrtime()
const newStartUsage = process.cpuUsage()
@ -28,8 +28,8 @@ const cpuUsage = (startTime, startUsage) => {
}
export default callback => {
const initCpuUsage = (startTime, startUsage) => {
const { cpuPercent, newStartTime, newStartUsage } = cpuUsage(startTime, startUsage)
const initCpuUsage = async (startTime, startUsage) => {
const { cpuPercent, newStartTime, newStartUsage } = await cpuUsage(startTime, startUsage)
callback(cpuPercent)

Loading…
Cancel
Save