no-progress-while-running.js 541 B

1234567891011121314151617181920212223
  1. 'use strict'
  2. var log = require('npmlog')
  3. var progressEnabled
  4. var running = 0
  5. var startRunning = exports.startRunning = function () {
  6. if (progressEnabled == null) progressEnabled = log.progressEnabled
  7. if (progressEnabled) log.disableProgress()
  8. ++running
  9. }
  10. var stopRunning = exports.stopRunning = function () {
  11. --running
  12. if (progressEnabled && running === 0) log.enableProgress()
  13. }
  14. exports.tillDone = function noProgressTillDone (cb) {
  15. startRunning()
  16. return function () {
  17. stopRunning()
  18. cb.apply(this, arguments)
  19. }
  20. }