要不 promisify 一下原生数组?

2021-01-04 17:08:25 +08:00
 benb

这样 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

1673 次点击
所在节点    JavaScript
2 条回复
gouflv
2021-01-04 17:15:18 +08:00
看到了 rxjs 的影子
xiaoming1992
2021-01-04 18:24:39 +08:00
粗略瞄了一眼,挺有意思的

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/741584

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX