pulse-till-done.js 405 B

1234567891011121314151617181920212223242526
  1. const log = require('npmlog')
  2. let pulseTimer = null
  3. const withPromise = async (promise) => {
  4. pulseStart()
  5. try {
  6. return await promise
  7. } finally {
  8. pulseStop()
  9. }
  10. }
  11. const pulseStart = () => {
  12. pulseTimer = pulseTimer || setInterval(() => {
  13. log.gauge.pulse('')
  14. }, 150)
  15. }
  16. const pulseStop = () => {
  17. clearInterval(pulseTimer)
  18. pulseTimer = null
  19. }
  20. module.exports = {
  21. withPromise,
  22. }