File: pulse-till-done.js

package info (click to toggle)
npm 9.2.0~ds1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 318,988 kB
  • sloc: javascript: 167,820; sh: 194; makefile: 52; perl: 11
file content (26 lines) | stat: -rw-r--r-- 412 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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,
}