summaryrefslogtreecommitdiff
path: root/deps/npm/lib/utils/pulse-till-done.js
blob: 26692413068a535427266449233981e679b0679f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
'use strict'
var validate = require('aproba')
var log = require('npmlog')

var pulsers = 0
var pulse

module.exports = function (prefix, cb) {
  validate('SF', [prefix, cb])
  if (!prefix) prefix = 'network'
  if (!pulsers++) {
    pulse = setInterval(function () {
      log.gauge.pulse(prefix)
    }, 250)
  }
  return function () {
    if (!--pulsers) {
      clearInterval(pulse)
    }
    cb.apply(null, arguments)
  }
}