SOURCE

// //手写异步请求调度函数
// function requestUrls(urls, limit = 5, reCount = 3) {
//   limit = Math.max(1, limit | 0)
//   const results = new Array(urls.length)
//   let nextIndex = 0
//   let finished = 0

//   return new Promise((resolve) => {
//     const runOne = async (i) => {
//       let attempts = 0
//       while (true) {
//         try {
//           const res = await axios.get(urls[i])
//           results[i] = { status: 'fulfilled', value: res }
//           break
//         } catch (err) {
//           if (attempts >= reCount) {
//             results[i] = { status: 'rejected', reason: err }
//             break
//           }
//           attempts++
//         }
//       }
//       finished++
//       if (finished === urls.length) {
//         resolve(results)
//       } else if (nextIndex < urls.length) {
//         runOne(nextIndex++)
//       }
//     }

//     const start = Math.min(limit, urls.length)
//     for (let i = 0; i < start; i++) {
//       runOne(i)
//     }
//     nextIndex = start
//   })
// }

//手写promise.allSettled(在promise.all基础上修改)
// function allSettled(promises) {
//     const arr = Array.from(promises)
//     if (arr.length == 0) {
//         return Promise.resolve([])
//     }
//     let result = new Array(arr.length)
//     let count = 0
//     return new Promise((resolve, reject) => {
//         arr.forEach((p, index) => {
//             Promise.resolve(p).then((value) => {
//                 result[index] = { status: 'fulfilled', value }
//                 if (++count == arr.length) {
//                     resolve(result)
//                 }
//             },
//                 (reason) => {
//                     result[index] = { status: 'rejected', reason }
//                     if (++count == arr.length) {
//                         resolve(result)
//                     }
//                 })

//         })

//     })
// }
console 命令行工具 X clear

                    
>
console