让我们说,我有一系列的承诺,每个元素都会对一个视图的图像(png)进行AJAX调用。
const images = Promise.all(views.map(view => {
return fetch(`/sites/${siteId}/views/${view.id}/image/`);
}));
是否有可能使用Promise.all检查承诺解决方案的当前状态?如果没有,还有其他办法吗?
例如,如果下载了10/20张图片,我想向用户提供反馈,我们已经为他下载了50%的图片。
答案 0 :(得分:11)
只要承诺解决,只需递增一个变量:
CASE
WHEN POdate IS NULL THEN CAST(WOdate AS varchar (25))
WHEN WOdate IS NULL THEN CAST (POdate AS varchar (25))
WHEN POdate > WOdate THEN CAST (WOdate AS varchar (25))
WHEN POdate < WOdate THEN CAST (POdate AS varchar (25))
ELSE 'No Planned Stock'
END AS StockDueIn
答案 1 :(得分:1)
无需使用setInterval
。仅在更新进度时更新进度。
const promises = views.map(view => fetch (`/sites/${siteId}/views/${view.id}/image/`));
const images = Promise.all(promises);
let progress = 0;
promises.forEach(p => p.then(() => {
progress++;
console.log(progress / promises.length * 100 + "%");
}));