Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/utils/pulse-till-done.js')
-rw-r--r--lib/utils/pulse-till-done.js49
1 files changed, 17 insertions, 32 deletions
diff --git a/lib/utils/pulse-till-done.js b/lib/utils/pulse-till-done.js
index 13147bae1..a88b8aacd 100644
--- a/lib/utils/pulse-till-done.js
+++ b/lib/utils/pulse-till-done.js
@@ -1,41 +1,26 @@
const log = require('npmlog')
-let pulsers = 0
-let pulse
+let pulseTimer = null
+const withPromise = async (promise) => {
+ pulseStart()
+ try {
+ return await promise
+ } finally {
+ pulseStop()
+ }
+}
-function pulseStart (prefix) {
- if (++pulsers > 1)
- return
- pulse = setInterval(function () {
- log.gauge.pulse(prefix)
+const pulseStart = () => {
+ pulseTimer = pulseTimer || setInterval(() => {
+ log.gauge.pulse('')
}, 150)
}
-function pulseStop () {
- if (--pulsers > 0)
- return
- clearInterval(pulse)
-}
-module.exports = function (prefix, cb) {
- if (!prefix)
- prefix = 'network'
- pulseStart(prefix)
- return (er, ...args) => {
- pulseStop()
- cb(er, ...args)
- }
+const pulseStop = () => {
+ clearInterval(pulseTimer)
+ pulseTimer = null
}
-const pulseWhile = async (prefix, promise) => {
- if (!promise) {
- promise = prefix
- prefix = ''
- }
- pulseStart(prefix)
- try {
- return await promise
- } finally {
- pulseStop()
- }
+module.exports = {
+ withPromise,
}
-module.exports.withPromise = pulseWhile