JSスニペット 非同期関連
複数非同期通信のスマートなawait
await並べるだけだと順次通信してしまうので工夫する
const get_schedules_days=async()=>{
//これだと遅い
//await get_a_schedules();
//await get_b_schedules();
let results=[];
results.push(get_a_schedules());
results.push(get_b_schedules());
await Promise.all(results);
schedules_days_show();
}
const get_a_schedules=async()=>{
await $.ajax({
type : "GET",
url : "./rest/get_a_schedules/",
data : {
},
dataType : "json",
cache : false
}).done(function (data) {
}).fail(function (data) {
}).always(function (data) {
});
}
const get_b_schedules=async()=>{
await $.ajax({
type : "GET",
url : "./rest/get_b_schedules/",
data : {
},
dataType : "json",
cache : false
}).done(function (data) {
}).fail(function (data) {
}).always(function (data) {
});
}
コメント
コメントを投稿