ora promise wrap

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

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