a-synchronous / a-synchronous/rubico

reduce.pool

未關閉
#159 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
enhancement
主要語言
JavaScript
星號
283
分支
17
PR 合併指標
30 天內沒有已合併 PR

描述

```coffeescript
reduce.pool(maxConcurrency number, foldable Foldable, init function|any) -> Promise|any
```

`reduce` with limited concurrency.

```javascript
// (from number, to number) => AsyncIterator
const asyncRange = async function* (from, to) {
let number = from
while (++number < to) {
yield number
}
}

const asyncAdd = async (a, b) => a + b

reduce.pool(20, map(tap(console.log))(asyncAdd), 0)(asyncRange(1, 1000)).then(console.log)
// 1
// 2
// 3
// ...
// 999
// 499499
```

貢獻指南

開啟貢獻指南

研究方向

查看程式碼庫中現有的 reduce 實作,以了解其結構。新的 reduce.pool 函式需要在處理 foldable(例如 async iterator)時限制並行。首先檢查 async iterator 的處理方式以及 promises 的管理方式。範例使用了 map、tap 和 asyncAdd;檢查這些 utilities 如何整合。實作並行控制,可能使用 worker pool,或限制 promises 的平行執行。使用提供的 asyncRange 範例進行測試,確保它依序記錄數字直到 999,並加總得到 499499。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
coffeescript, javascript
領域
backend-api-design
Issue 類型
功能
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。