私は2つの簡単な方法を持っています:
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