gxd-vue-library
Version:
依赖与element Ui插件库,聚福宝福利PC端插件库
80 lines (69 loc) • 1.53 kB
JavaScript
;
class Task {
constructor(array=[], done){
this.taskFncList = array.filter(item=>{
return typeof item === "function";
});
if (typeof done === "function") {
this.done = done;
}
this.count = 0;
}
push(fnc){
if(typeof fnc === "function") {
this.taskFncList.push(fnc);
}
}
exec(){
if (this.taskFncList.length > 0) {
this.taskFncList.shift()(()=>{
this.exec();
}, this.count);
this.count++;
} else {
this.done();
}
}
init(done){
if (typeof done === "function") {
this.done = done;
}
this.exec()
}
}
module.exports = Task;
/**
const utils = require('./build/lib/utils');
const Task = require('./build/lib/Task');
const execSync = require('child_process').execSync;
const clog = require('./build/clog');
function checkStatus() {
return new Promise((resolve, reject)=>{
clog(`cnpm sync gxd-uni-library-editx`, 'cyan');
let result = execSync(`cnpm sync gxd-uni-library-editx`, {stdio: 'inherit'});
clog(`发布完成`, 'cyan');
if(!result) resolve();
else throw Error(result);
});
}
const handle = (i)=>{
return new Promise((resolve)=>{
setTimeout(()=>{
console.log(i);
resolve()
}, utils.random(1, 5)*1000)
})
};
const task = new Task();
[1,2].map(item=>{
task.push(async (next, index)=>{
console.log(index);
await checkStatus();
await handle(item);
next()
});
});
task.init(() => {
console.log('done')
});
*/