我正在重写一个批量执行 REST API 调用的应用程序,例如一次执行 10 个,总共 500 个调用。我需要帮助将使用 ES6+ 函数的 js 函数降级为 ES5 等效函数(基本上没有箭头函数或 async/await)。
在我原来的应用程序中,在支持 ES6+ 函数(箭头函数、异步/等待等)的环境中使用,我的工作函数如下:
原函数:
// Async function to process rest calls in batches
const searchIssues = async (restCalls, batchSize, loadingText) => {
const restCallsLength = restCalls.length;
var issues = [];
for (let i = 0; i < restCallsLength; i += batchSize) {
//create batch of requests
var requests = restCalls.slice(i, i + batchSize).map((restCall) => {
return fetch(restCall)
.then(function(fieldResponse) {
return fieldResponse.json()
})
.then(d => { …Run Code Online (Sandbox Code Playgroud)