node/deps/npm/lib/utils/pulse-till-done.js
npm team b323cec78f deps: upgrade npm to 8.2.0
PR-URL: https://github.com/nodejs/node/pull/41065
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2021-12-05 08:31:02 -08:00

27 lines
412 B
JavaScript

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,
}