我有两种简单的方法:
function do(x,y){
if(x){
XHR1().success();
}
if(y){
XHR2().success();
}
}
function done(){
return something;
}
现在我只想确保在完成done()
时调用do()
(**do() 方法包含对 Mysql DB 的异步请求)
我怎样才能做到这一点?**
显然这不会按顺序排列这些方法:
do(x=1,y=1);
done(); //this can run also if do() has not finished yet
所以我尝试了:
function do(x,y,_callback){
if(x){
XHR1().success();
}
if(y){
XHR2().success();
}
_callback();
}
function done(){
return something;
}
do(x=1,y=1,done()); // this won't work the same cause callback is not dependent by XHR response
这就是我用于承诺https://github.com/tildeio/rsvp.js/#arrays-of-promises