-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- remove spawn util, refactor help command - add tests for read-user-info, minor refactor - add tests for pulse-till-done util, refactor - add tests for otplease util - add tests for open-url util - remove unused no-progress-while-running util PR-URL: npm#2601 Credit: @nlf Close: npm#2601 Reviewed-by: @ruyadorno, @wraithgar
- Loading branch information
Showing
11 changed files
with
573 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.