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'); const ora = require('ora');
module.exports = async (text, promise, callback) => { module.exports = async (text, promise, callback) => {
return new Promise(async (resolve, reject) => {
let spin = ora(text).start(); let spin = ora(text).start();
await promise return await promise
.catch(e => callback(spin, e)) .catch(e => {
spin.stop();
spin.clear();
return reject(e)
})
.then((...args) => { .then((...args) => {
spin.stop(); spin.stop();
spin.clear(); spin.clear();
callback(spin, args); return callback ? resolve(callback(spin, args)) : resolve(true);
});
}); });
}; };
Loading…
Cancel
Save