Async-2.js
· 300 B · JavaScript
原始檔案
import { mapLimit } from "async-es";
// ...or ES2017 async functions
mapLimit(urls, 5, async function(url) {
const response = await fetch(url)
return response.body
}, (err, results) => {
if (err) throw err
// results is now an array of the response bodies
console.log(results)
})
1 | import { mapLimit } from "async-es"; |
2 | |
3 | // ...or ES2017 async functions |
4 | mapLimit(urls, 5, async function(url) { |
5 | const response = await fetch(url) |
6 | return response.body |
7 | }, (err, results) => { |
8 | if (err) throw err |
9 | // results is now an array of the response bodies |
10 | console.log(results) |
11 | }) |