Skip to content

Instantly share code, notes, and snippets.

@dyrkow
Created January 21, 2018 11:50
Show Gist options
  • Save dyrkow/1f831dc332c08ca2184efaed38e5dce2 to your computer and use it in GitHub Desktop.
Save dyrkow/1f831dc332c08ca2184efaed38e5dce2 to your computer and use it in GitHub Desktop.
//Async func run one by one
function wait(callback) {
var queue = [];
function _next() {
var cb = queue.shift(),
args = [].slice.call(arguments);
if (cb) {
cb(_next,args);
}
}
setTimeout(_next, 0);
var then = function(cb) {
queue.push(cb);
return { then: then }
}
return then(callback);
}
//Использование
wait((next)=>{
startSession(cnf);
next();
})
.then((next)=>{
getAuthData().then((userData)=>{next(userData)});
})
.then((next,userData)=>{
const statusLoad = new Spinner('Auth in vk...');
statusLoad.start();
login(userData).then((user)=>{
statusLoad.stop();
clear();
next(user);
});
})
.then((next, user)=>{
drawMainMenu(cnf).then((answer)=>{
next(user, answer);
});
})
.then((next, answer)=>{
actions[answer[1].result](answer[0][0])
.then((mes)=>{
for(i=0,l=mes.items.length; i<l; i++){
console.dir(mes.items[i]);
}
});
// next(user);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment