技术解析

要不 promisify 一下原生数组?
0
2021-08-11 00:57:16
idczone

这样 map 、filter 、reduce 这些方法也可以传递 async 函数了……

import Prray from 'prray'

// 1) create
const urls = Prray.from(['www.google.com', 'npmjs.org'])


// 2) async method
const responses = await urls.mapAsync(fetch)


// 3) method chaining with both normal and async methods
await urls
  .concat(['github.com', 'wikipedia.org'])
  .mapAsync(request)
  .filter(isValidHtml)
  .forEachAsync(saveToDB)


// 4) concurrency limit
const responses = await urls.mapAsync(fetch, { concurrency: 10 })

工具包的文档和路径: https://github.com/Bin-Huang/prray


看到了 rxjs 的影子

粗略瞄了一眼,挺有意思的

数据地带为您的网站提供全球顶级IDC资源
在线咨询
专属客服