fix pulseWhileDone promise handling · npm/cli@10fcff7 (original) (raw)

Original file line number Diff line number Diff line change
@@ -25,18 +25,17 @@ module.exports = function (prefix, cb) {
25 25 cb(er, ...args)
26 26 }
27 27 }
28 -module.exports.withPromise = pulseWhile
29 28
30 -function pulseWhile (prefix, promise) {
29 +const pulseWhile = async (prefix, promise) => {
31 30 if (!promise) {
32 31 promise = prefix
33 32 prefix = ''
34 33 }
35 34 pulseStart(prefix)
36 -return Promise.resolve(promise)
37 -.then(() => pulseStop())
38 -.catch(er => {
39 -pulseStop()
40 -throw er
41 -})
35 +try {
36 +return await promise
37 +} finally {
38 +pulseStop()
39 +}
42 40 }
41 +module.exports.withPromise = pulseWhile