ora promise wrap

v2
Kit Kasune 2 years ago
parent 3b3d64cf62
commit 2dadce7391
  1. 12
      src/util/log/ora.js

@ -1,12 +1,18 @@
const ora = require('ora');
module.exports = async (text, promise, callback) => {
return new Promise(async (resolve, reject) => {
let spin = ora(text).start();
await promise
.catch(e => callback(spin, e))
return await promise
.catch(e => {
spin.stop();
spin.clear();
return reject(e)
})
.then((...args) => {
spin.stop();
spin.clear();
callback(spin, args);
return callback ? resolve(callback(spin, args)) : resolve(true);
});
});
};
Loading…
Cancel
Save