1.0.0 • Published 3 years ago
node-on-idle v1.0.0
on-idle
Trigger an idle
event when the Node.js process is in the idle status!
You need Node.js >= 12.9.0 to run this module since perf_hooks
are used under the hood.
Usage
The idle
event is fired no more than 1 time every throttling
ms and only when idleLimit
ms has been expired.
The check of the limit is performed every sampleInterval
ms.
const onIdle = require('node-on-idle')
const eventEmitter = onIdle()
eventEmitter.on('idle', function (idleMs) {
// do some stuff when the process is in idle
})
// You can set the options like this:
const eventEmitter = onIdle({
idleLimit: 2000, // default value
throttling: 10000, // default value
sampleInterval: 1000 // default value
})
The sampling will start when the first listener will be appended to the EventEmitter returned.
License
Licensed under MIT.
1.0.0
3 years ago