smart-energy-monitor/software/flow/node_modules/npm/lib/utils/pulse-till-done.js

27 lines
412 B
JavaScript
Raw Normal View History

2023-02-23 15:38:30 +01:00
const log = require('./log-shim.js')
let pulseTimer = null
const withPromise = async (promise) => {
pulseStart()
try {
return await promise
} finally {
pulseStop()
}
}
const pulseStart = () => {
pulseTimer = pulseTimer || setInterval(() => {
log.gauge.pulse('')
}, 150)
}
const pulseStop = () => {
clearInterval(pulseTimer)
pulseTimer = null
}
module.exports = {
withPromise,
}