0
Q
AJAX请求池
A
回答
1
您可以使用Array.prototype.splice()
,Promise.all()
,fetch()
一次执行N
个请求。
let data = [FormData, FormData, ..];
let N = 5;
let pool = data.splice(0, N);
let processData = requests =>
Promise.all(
requests.map(fd =>
fetch("/path/to/server", {
method: "POST",
body: fd
})
.then(response => response.ok)
)
)
.then(responses => responses.every(result => result))
.then(result => {
if (result) {
if (data.length) {
pool = data.splice(0, N);
return true
}
}
return "complete"
});
let fn = next => next === true ? processData(pool).then(fn) : next;
processData(pool)
.then(fn)
.then(complete => console.log(complete))
.catch(err => console.log(err));
的jsfiddle https://jsfiddle.net/ce1kzu52/5/
也可以处理该阵列,而不调度功能processData
再次调用如果任何元件在阵列剩余。
相关问题
- 1. 新Ajax请求onComplete每个Ajax请求
- 2. Ajax请求中的jQuery Ajax请求
- 3. 春 - 请求从对象池
- 4. Golang HTTP请求工作池
- 5. Acts_As_Votable Ajax请求
- 6. Trigger.io Ajax请求
- 7. rails ajax请求
- 8. 从Ajax请求
- 9. Magento ajax请求
- 10. jQuery - AJAX请求
- 11. Ajax请求Codeigniter
- 12. Ajax请求
- 13. AJAX XMLHTTP请求
- 14. Rails Ajax请求
- 15. spring ajax请求
- 16. AJAX长请求
- 17. MVC4 Ajax请求
- 18. Cakephp Ajax请求
- 19. Highchart ajax请求
- 20. Jqplot Ajax请求
- 21. AJAX请求
- 22. getJson ajax请求
- 23. resteasy ajax请求
- 24. jquery AJAX请求
- 25. Mootools ajax请求
- 26. ajax请求jqmobi
- 27. GET ajax请求
- 28. Ajax请求
- 29. Ajax请求
- 30. Ghost Ajax请求
你是什么意思的“池”? –
如果你在承诺中包装你的AJAX请求,你可以使用[这个答案](http://stackoverflow.com/questions/39863062/how-can-i-call-one-asynchronous-function-in-a-group-方式/ 39863245#39863245)来解决这个问题。 – SimpleJ
按池我的意思是XMLHttpRequest对象的数组。 – user41451