@vielzeug/toolkit 1.1.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +419 -0
- package/dist/array/chunk.cjs +2 -2
- package/dist/array/chunk.cjs.map +1 -1
- package/dist/array/chunk.d.ts +29 -0
- package/dist/array/chunk.d.ts.map +1 -0
- package/dist/array/chunk.js +22 -24
- package/dist/array/chunk.js.map +1 -1
- package/dist/array/contains.cjs +2 -2
- package/dist/array/contains.cjs.map +1 -1
- package/dist/array/contains.d.ts +19 -0
- package/dist/array/contains.d.ts.map +1 -0
- package/dist/array/contains.js +12 -9
- package/dist/array/contains.js.map +1 -1
- package/dist/array/fold.cjs +2 -0
- package/dist/array/fold.cjs.map +1 -0
- package/dist/array/fold.d.ts +21 -0
- package/dist/array/fold.d.ts.map +1 -0
- package/dist/array/fold.js +19 -0
- package/dist/array/fold.js.map +1 -0
- package/dist/array/group.cjs +2 -2
- package/dist/array/group.cjs.map +1 -1
- package/dist/array/group.d.ts +19 -0
- package/dist/array/group.d.ts.map +1 -0
- package/dist/array/group.js +18 -15
- package/dist/array/group.js.map +1 -1
- package/dist/array/index.d.ts +16 -0
- package/dist/array/index.d.ts.map +1 -0
- package/dist/array/keyBy.cjs +2 -0
- package/dist/array/keyBy.cjs.map +1 -0
- package/dist/array/keyBy.d.ts +20 -0
- package/dist/array/keyBy.d.ts.map +1 -0
- package/dist/array/keyBy.js +19 -0
- package/dist/array/keyBy.js.map +1 -0
- package/dist/array/list.cjs +2 -2
- package/dist/array/list.cjs.map +1 -1
- package/dist/array/list.d.ts +58 -0
- package/dist/array/list.d.ts.map +1 -0
- package/dist/array/list.js +103 -106
- package/dist/array/list.js.map +1 -1
- package/dist/array/pick.cjs +2 -2
- package/dist/array/pick.cjs.map +1 -1
- package/dist/array/pick.d.ts +19 -0
- package/dist/array/pick.d.ts.map +1 -0
- package/dist/array/pick.js +15 -14
- package/dist/array/pick.js.map +1 -1
- package/dist/array/remoteList.cjs +2 -2
- package/dist/array/remoteList.cjs.map +1 -1
- package/dist/array/remoteList.d.ts +64 -0
- package/dist/array/remoteList.d.ts.map +1 -0
- package/dist/array/remoteList.js +121 -122
- package/dist/array/remoteList.js.map +1 -1
- package/dist/array/replace.cjs +2 -0
- package/dist/array/replace.cjs.map +1 -0
- package/dist/array/replace.d.ts +20 -0
- package/dist/array/replace.d.ts.map +1 -0
- package/dist/array/replace.js +19 -0
- package/dist/array/replace.js.map +1 -0
- package/dist/array/rotate.cjs +2 -0
- package/dist/array/rotate.cjs.map +1 -0
- package/dist/array/rotate.d.ts +22 -0
- package/dist/array/rotate.d.ts.map +1 -0
- package/dist/array/rotate.js +19 -0
- package/dist/array/rotate.js.map +1 -0
- package/dist/array/search.cjs +2 -2
- package/dist/array/search.cjs.map +1 -1
- package/dist/array/search.d.ts +19 -0
- package/dist/array/search.d.ts.map +1 -0
- package/dist/array/search.js +23 -13
- package/dist/array/search.js.map +1 -1
- package/dist/array/select.cjs +2 -2
- package/dist/array/select.cjs.map +1 -1
- package/dist/array/select.d.ts +21 -0
- package/dist/array/select.d.ts.map +1 -0
- package/dist/array/select.js +16 -15
- package/dist/array/select.js.map +1 -1
- package/dist/array/sort.cjs +2 -2
- package/dist/array/sort.cjs.map +1 -1
- package/dist/array/sort.d.ts +26 -0
- package/dist/array/sort.d.ts.map +1 -0
- package/dist/array/sort.js +18 -12
- package/dist/array/sort.js.map +1 -1
- package/dist/array/toggle.cjs +2 -0
- package/dist/array/toggle.cjs.map +1 -0
- package/dist/array/toggle.d.ts +29 -0
- package/dist/array/toggle.d.ts.map +1 -0
- package/dist/array/toggle.js +9 -0
- package/dist/array/toggle.js.map +1 -0
- package/dist/array/uniq.cjs +2 -2
- package/dist/array/uniq.cjs.map +1 -1
- package/dist/array/uniq.d.ts +21 -0
- package/dist/array/uniq.d.ts.map +1 -0
- package/dist/array/uniq.js +15 -17
- package/dist/array/uniq.js.map +1 -1
- package/dist/async/attempt.cjs +2 -2
- package/dist/async/attempt.cjs.map +1 -1
- package/dist/async/attempt.d.ts +40 -0
- package/dist/async/attempt.d.ts.map +1 -0
- package/dist/async/attempt.js +19 -14
- package/dist/async/attempt.js.map +1 -1
- package/dist/async/defer.cjs +2 -2
- package/dist/async/defer.cjs.map +1 -1
- package/dist/async/defer.d.ts +23 -0
- package/dist/async/defer.d.ts.map +1 -0
- package/dist/async/defer.js +12 -9
- package/dist/async/defer.js.map +1 -1
- package/dist/async/index.d.ts +12 -0
- package/dist/async/index.d.ts.map +1 -0
- package/dist/async/parallel.cjs +2 -2
- package/dist/async/parallel.cjs.map +1 -1
- package/dist/async/parallel.d.ts +31 -0
- package/dist/async/parallel.d.ts.map +1 -0
- package/dist/async/parallel.js +26 -27
- package/dist/async/parallel.js.map +1 -1
- package/dist/async/pool.cjs +2 -2
- package/dist/async/pool.cjs.map +1 -1
- package/dist/async/pool.d.ts +21 -0
- package/dist/async/pool.d.ts.map +1 -0
- package/dist/async/pool.js +23 -21
- package/dist/async/pool.js.map +1 -1
- package/dist/async/predict.cjs +2 -2
- package/dist/async/predict.cjs.map +1 -1
- package/dist/async/predict.d.ts +24 -0
- package/dist/async/predict.d.ts.map +1 -0
- package/dist/async/predict.js +10 -12
- package/dist/async/predict.js.map +1 -1
- package/dist/async/queue.cjs +2 -2
- package/dist/async/queue.cjs.map +1 -1
- package/dist/async/queue.d.ts +43 -0
- package/dist/async/queue.d.ts.map +1 -0
- package/dist/async/queue.js +52 -56
- package/dist/async/queue.js.map +1 -1
- package/dist/async/race.cjs +2 -2
- package/dist/async/race.cjs.map +1 -1
- package/dist/async/race.d.ts +16 -0
- package/dist/async/race.d.ts.map +1 -0
- package/dist/async/race.js +8 -7
- package/dist/async/race.js.map +1 -1
- package/dist/async/retry.cjs +2 -2
- package/dist/async/retry.cjs.map +1 -1
- package/dist/async/retry.d.ts +32 -0
- package/dist/async/retry.d.ts.map +1 -0
- package/dist/async/retry.js +19 -24
- package/dist/async/retry.js.map +1 -1
- package/dist/async/scheduler.cjs +2 -0
- package/dist/async/scheduler.cjs.map +1 -0
- package/dist/async/scheduler.d.ts +51 -0
- package/dist/async/scheduler.d.ts.map +1 -0
- package/dist/async/scheduler.js +43 -0
- package/dist/async/scheduler.js.map +1 -0
- package/dist/async/sleep.cjs +2 -2
- package/dist/async/sleep.cjs.map +1 -1
- package/dist/async/sleep.d.ts +16 -0
- package/dist/async/sleep.d.ts.map +1 -0
- package/dist/async/sleep.js +11 -11
- package/dist/async/sleep.js.map +1 -1
- package/dist/async/waitFor.cjs +2 -2
- package/dist/async/waitFor.cjs.map +1 -1
- package/dist/async/waitFor.d.ts +33 -0
- package/dist/async/waitFor.d.ts.map +1 -0
- package/dist/async/waitFor.js +29 -36
- package/dist/async/waitFor.js.map +1 -1
- package/dist/date/expires.cjs +2 -2
- package/dist/date/expires.cjs.map +1 -1
- package/dist/date/expires.d.ts +15 -0
- package/dist/date/expires.d.ts.map +1 -0
- package/dist/date/expires.js +11 -10
- package/dist/date/expires.js.map +1 -1
- package/dist/date/index.d.ts +4 -0
- package/dist/date/index.d.ts.map +1 -0
- package/dist/date/interval.cjs +2 -2
- package/dist/date/interval.cjs.map +1 -1
- package/dist/date/interval.d.ts +25 -0
- package/dist/date/interval.d.ts.map +1 -0
- package/dist/date/interval.js +31 -37
- package/dist/date/interval.js.map +1 -1
- package/dist/date/timeDiff.cjs +2 -2
- package/dist/date/timeDiff.cjs.map +1 -1
- package/dist/date/timeDiff.d.ts +24 -0
- package/dist/date/timeDiff.d.ts.map +1 -0
- package/dist/date/timeDiff.js +58 -25
- package/dist/date/timeDiff.js.map +1 -1
- package/dist/function/assert.cjs +2 -3
- package/dist/function/assert.cjs.map +1 -1
- package/dist/function/assert.d.ts +38 -0
- package/dist/function/assert.d.ts.map +1 -0
- package/dist/function/assert.js +13 -11
- package/dist/function/assert.js.map +1 -1
- package/dist/function/assertParams.cjs +2 -2
- package/dist/function/assertParams.cjs.map +1 -1
- package/dist/function/assertParams.d.ts +24 -0
- package/dist/function/assertParams.d.ts.map +1 -0
- package/dist/function/assertParams.js +13 -12
- package/dist/function/assertParams.js.map +1 -1
- package/dist/function/compare.cjs +2 -2
- package/dist/function/compare.cjs.map +1 -1
- package/dist/function/compare.d.ts +23 -0
- package/dist/function/compare.d.ts.map +1 -0
- package/dist/function/compare.js +22 -21
- package/dist/function/compare.js.map +1 -1
- package/dist/function/compareBy.cjs +2 -2
- package/dist/function/compareBy.cjs.map +1 -1
- package/dist/function/compareBy.d.ts +24 -0
- package/dist/function/compareBy.d.ts.map +1 -0
- package/dist/function/compareBy.js +15 -14
- package/dist/function/compareBy.js.map +1 -1
- package/dist/function/compose.cjs +2 -2
- package/dist/function/compose.cjs.map +1 -1
- package/dist/function/compose.d.ts +22 -0
- package/dist/function/compose.d.ts.map +1 -0
- package/dist/function/compose.js +10 -13
- package/dist/function/compose.js.map +1 -1
- package/dist/function/curry.cjs +2 -2
- package/dist/function/curry.cjs.map +1 -1
- package/dist/function/curry.d.ts +21 -0
- package/dist/function/curry.d.ts.map +1 -0
- package/dist/function/curry.js +8 -7
- package/dist/function/curry.js.map +1 -1
- package/dist/function/debounce.cjs +2 -2
- package/dist/function/debounce.cjs.map +1 -1
- package/dist/function/debounce.d.ts +12 -0
- package/dist/function/debounce.d.ts.map +1 -0
- package/dist/function/debounce.js +34 -26
- package/dist/function/debounce.js.map +1 -1
- package/dist/function/fp.cjs +2 -2
- package/dist/function/fp.cjs.map +1 -1
- package/dist/function/fp.d.ts +24 -0
- package/dist/function/fp.d.ts.map +1 -0
- package/dist/function/fp.js +6 -10
- package/dist/function/fp.js.map +1 -1
- package/dist/function/index.d.ts +13 -0
- package/dist/function/index.d.ts.map +1 -0
- package/dist/function/memo.cjs +2 -2
- package/dist/function/memo.cjs.map +1 -1
- package/dist/function/memo.d.ts +30 -0
- package/dist/function/memo.d.ts.map +1 -0
- package/dist/function/memo.js +16 -24
- package/dist/function/memo.js.map +1 -1
- package/dist/function/once.cjs +2 -2
- package/dist/function/once.cjs.map +1 -1
- package/dist/function/once.d.ts +24 -0
- package/dist/function/once.d.ts.map +1 -0
- package/dist/function/once.js +10 -10
- package/dist/function/once.js.map +1 -1
- package/dist/function/pipe.cjs +2 -2
- package/dist/function/pipe.cjs.map +1 -1
- package/dist/function/pipe.d.ts +23 -0
- package/dist/function/pipe.d.ts.map +1 -0
- package/dist/function/pipe.js +10 -10
- package/dist/function/pipe.js.map +1 -1
- package/dist/function/throttle.cjs +2 -2
- package/dist/function/throttle.cjs.map +1 -1
- package/dist/function/throttle.d.ts +21 -0
- package/dist/function/throttle.d.ts.map +1 -0
- package/dist/function/throttle.js +45 -37
- package/dist/function/throttle.js.map +1 -1
- package/dist/index.cjs +1 -2
- package/dist/index.d.ts +77 -2813
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +75 -253
- package/dist/math/abs.cjs +2 -2
- package/dist/math/abs.cjs.map +1 -1
- package/dist/math/abs.d.ts +17 -0
- package/dist/math/abs.d.ts.map +1 -0
- package/dist/math/abs.js +7 -6
- package/dist/math/abs.js.map +1 -1
- package/dist/math/allocate.cjs +2 -2
- package/dist/math/allocate.cjs.map +1 -1
- package/dist/math/allocate.d.ts +24 -0
- package/dist/math/allocate.d.ts.map +1 -0
- package/dist/math/allocate.js +20 -28
- package/dist/math/allocate.js.map +1 -1
- package/dist/math/average.cjs +2 -2
- package/dist/math/average.cjs.map +1 -1
- package/dist/math/average.d.ts +16 -0
- package/dist/math/average.d.ts.map +1 -0
- package/dist/math/average.js +13 -24
- package/dist/math/average.js.map +1 -1
- package/dist/math/clamp.cjs +2 -2
- package/dist/math/clamp.cjs.map +1 -1
- package/dist/math/clamp.d.ts +18 -0
- package/dist/math/clamp.d.ts.map +1 -0
- package/dist/math/clamp.js +7 -6
- package/dist/math/clamp.js.map +1 -1
- package/dist/math/distribute.cjs +2 -2
- package/dist/math/distribute.cjs.map +1 -1
- package/dist/math/distribute.d.ts +24 -0
- package/dist/math/distribute.d.ts.map +1 -0
- package/dist/math/distribute.js +14 -17
- package/dist/math/distribute.js.map +1 -1
- package/dist/math/index.d.ts +14 -0
- package/dist/math/index.d.ts.map +1 -0
- package/dist/math/linspace.cjs +2 -0
- package/dist/math/linspace.cjs.map +1 -0
- package/dist/math/linspace.d.ts +19 -0
- package/dist/math/linspace.d.ts.map +1 -0
- package/dist/math/linspace.js +11 -0
- package/dist/math/linspace.js.map +1 -0
- package/dist/math/max.cjs +2 -2
- package/dist/math/max.cjs.map +1 -1
- package/dist/math/max.d.ts +23 -0
- package/dist/math/max.d.ts.map +1 -0
- package/dist/math/max.js +10 -11
- package/dist/math/max.js.map +1 -1
- package/dist/math/median.cjs +2 -2
- package/dist/math/median.cjs.map +1 -1
- package/dist/math/median.d.ts +17 -0
- package/dist/math/median.d.ts.map +1 -0
- package/dist/math/median.js +11 -10
- package/dist/math/median.js.map +1 -1
- package/dist/math/min.cjs +2 -2
- package/dist/math/min.cjs.map +1 -1
- package/dist/math/min.d.ts +23 -0
- package/dist/math/min.d.ts.map +1 -0
- package/dist/math/min.js +10 -11
- package/dist/math/min.js.map +1 -1
- package/dist/math/percent.cjs +2 -0
- package/dist/math/percent.cjs.map +1 -0
- package/dist/math/percent.d.ts +19 -0
- package/dist/math/percent.d.ts.map +1 -0
- package/dist/math/percent.js +8 -0
- package/dist/math/percent.js.map +1 -0
- package/dist/math/range.cjs +2 -2
- package/dist/math/range.cjs.map +1 -1
- package/dist/math/range.d.ts +23 -0
- package/dist/math/range.d.ts.map +1 -0
- package/dist/math/range.js +28 -17
- package/dist/math/range.js.map +1 -1
- package/dist/math/round.cjs +2 -2
- package/dist/math/round.cjs.map +1 -1
- package/dist/math/round.d.ts +21 -0
- package/dist/math/round.d.ts.map +1 -0
- package/dist/math/round.js +9 -8
- package/dist/math/round.js.map +1 -1
- package/dist/math/sum.cjs +2 -2
- package/dist/math/sum.cjs.map +1 -1
- package/dist/math/sum.d.ts +17 -0
- package/dist/math/sum.d.ts.map +1 -0
- package/dist/math/sum.js +11 -14
- package/dist/math/sum.js.map +1 -1
- package/dist/money/currency.cjs +2 -2
- package/dist/money/currency.cjs.map +1 -1
- package/dist/money/currency.d.ts +30 -0
- package/dist/money/currency.d.ts.map +1 -0
- package/dist/money/currency.js +19 -47
- package/dist/money/currency.js.map +1 -1
- package/dist/money/exchange.cjs +2 -2
- package/dist/money/exchange.cjs.map +1 -1
- package/dist/money/exchange.d.ts +29 -0
- package/dist/money/exchange.d.ts.map +1 -0
- package/dist/money/exchange.js +12 -12
- package/dist/money/exchange.js.map +1 -1
- package/dist/money/index.d.ts +4 -0
- package/dist/money/index.d.ts.map +1 -0
- package/dist/money/types.d.ts +9 -0
- package/dist/money/types.d.ts.map +1 -0
- package/dist/object/diff.cjs +2 -2
- package/dist/object/diff.cjs.map +1 -1
- package/dist/object/diff.d.ts +26 -0
- package/dist/object/diff.d.ts.map +1 -0
- package/dist/object/diff.js +19 -17
- package/dist/object/diff.js.map +1 -1
- package/dist/object/index.d.ts +9 -0
- package/dist/object/index.d.ts.map +1 -0
- package/dist/object/merge.cjs +2 -2
- package/dist/object/merge.cjs.map +1 -1
- package/dist/object/merge.d.ts +44 -0
- package/dist/object/merge.d.ts.map +1 -0
- package/dist/object/merge.js +27 -21
- package/dist/object/merge.js.map +1 -1
- package/dist/object/parseJSON.cjs +2 -2
- package/dist/object/parseJSON.cjs.map +1 -1
- package/dist/object/parseJSON.d.ts +32 -0
- package/dist/object/parseJSON.d.ts.map +1 -0
- package/dist/object/parseJSON.js +17 -18
- package/dist/object/parseJSON.js.map +1 -1
- package/dist/object/path.cjs +2 -2
- package/dist/object/path.cjs.map +1 -1
- package/dist/object/path.d.ts +32 -0
- package/dist/object/path.d.ts.map +1 -0
- package/dist/object/path.js +25 -23
- package/dist/object/path.js.map +1 -1
- package/dist/object/proxy.cjs +2 -0
- package/dist/object/proxy.cjs.map +1 -0
- package/dist/object/proxy.d.ts +30 -0
- package/dist/object/proxy.d.ts.map +1 -0
- package/dist/object/proxy.js +21 -0
- package/dist/object/proxy.js.map +1 -0
- package/dist/object/prune.cjs +2 -0
- package/dist/object/prune.cjs.map +1 -0
- package/dist/object/prune.d.ts +21 -0
- package/dist/object/prune.d.ts.map +1 -0
- package/dist/object/prune.js +31 -0
- package/dist/object/prune.js.map +1 -0
- package/dist/object/seek.cjs +2 -2
- package/dist/object/seek.cjs.map +1 -1
- package/dist/object/seek.d.ts +2 -0
- package/dist/object/seek.d.ts.map +1 -0
- package/dist/object/seek.js +25 -12
- package/dist/object/seek.js.map +1 -1
- package/dist/object/stash.cjs +2 -0
- package/dist/object/stash.cjs.map +1 -0
- package/dist/object/stash.d.ts +45 -0
- package/dist/object/stash.d.ts.map +1 -0
- package/dist/object/stash.js +99 -0
- package/dist/object/stash.js.map +1 -0
- package/dist/random/draw.cjs +2 -2
- package/dist/random/draw.cjs.map +1 -1
- package/dist/random/draw.d.ts +16 -0
- package/dist/random/draw.d.ts.map +1 -0
- package/dist/random/draw.js +13 -10
- package/dist/random/draw.js.map +1 -1
- package/dist/random/index.d.ts +5 -0
- package/dist/random/index.d.ts.map +1 -0
- package/dist/random/random.cjs +2 -2
- package/dist/random/random.cjs.map +1 -1
- package/dist/random/random.d.ts +14 -0
- package/dist/random/random.d.ts.map +1 -0
- package/dist/random/random.js +16 -9
- package/dist/random/random.js.map +1 -1
- package/dist/random/shuffle.cjs +2 -2
- package/dist/random/shuffle.cjs.map +1 -1
- package/dist/random/shuffle.d.ts +17 -0
- package/dist/random/shuffle.d.ts.map +1 -0
- package/dist/random/shuffle.js +18 -14
- package/dist/random/shuffle.js.map +1 -1
- package/dist/random/uuid.cjs +2 -2
- package/dist/random/uuid.cjs.map +1 -1
- package/dist/random/uuid.d.ts +12 -0
- package/dist/random/uuid.d.ts.map +1 -0
- package/dist/random/uuid.js +7 -9
- package/dist/random/uuid.js.map +1 -1
- package/dist/string/_caseUtils.cjs +2 -2
- package/dist/string/_caseUtils.cjs.map +1 -1
- package/dist/string/_caseUtils.d.ts +13 -0
- package/dist/string/_caseUtils.d.ts.map +1 -0
- package/dist/string/_caseUtils.js +8 -8
- package/dist/string/_caseUtils.js.map +1 -1
- package/dist/string/camelCase.cjs +2 -2
- package/dist/string/camelCase.cjs.map +1 -1
- package/dist/string/camelCase.d.ts +14 -0
- package/dist/string/camelCase.d.ts.map +1 -0
- package/dist/string/camelCase.js +8 -7
- package/dist/string/camelCase.js.map +1 -1
- package/dist/string/index.d.ts +7 -0
- package/dist/string/index.d.ts.map +1 -0
- package/dist/string/kebabCase.cjs +2 -2
- package/dist/string/kebabCase.cjs.map +1 -1
- package/dist/string/kebabCase.d.ts +15 -0
- package/dist/string/kebabCase.d.ts.map +1 -0
- package/dist/string/kebabCase.js +8 -7
- package/dist/string/kebabCase.js.map +1 -1
- package/dist/string/pascalCase.cjs +2 -2
- package/dist/string/pascalCase.cjs.map +1 -1
- package/dist/string/pascalCase.d.ts +15 -0
- package/dist/string/pascalCase.d.ts.map +1 -0
- package/dist/string/pascalCase.js +8 -7
- package/dist/string/pascalCase.js.map +1 -1
- package/dist/string/similarity.cjs +2 -2
- package/dist/string/similarity.cjs.map +1 -1
- package/dist/string/similarity.d.ts +20 -0
- package/dist/string/similarity.d.ts.map +1 -0
- package/dist/string/similarity.js +20 -36
- package/dist/string/similarity.js.map +1 -1
- package/dist/string/snakeCase.cjs +2 -2
- package/dist/string/snakeCase.cjs.map +1 -1
- package/dist/string/snakeCase.d.ts +15 -0
- package/dist/string/snakeCase.d.ts.map +1 -0
- package/dist/string/snakeCase.js +8 -7
- package/dist/string/snakeCase.js.map +1 -1
- package/dist/string/truncate.cjs +2 -2
- package/dist/string/truncate.cjs.map +1 -1
- package/dist/string/truncate.d.ts +28 -0
- package/dist/string/truncate.d.ts.map +1 -0
- package/dist/string/truncate.js +20 -17
- package/dist/string/truncate.js.map +1 -1
- package/dist/toolkit.cjs +2 -0
- package/dist/toolkit.cjs.map +1 -0
- package/dist/toolkit.js +1523 -0
- package/dist/toolkit.js.map +1 -0
- package/dist/typed/index.d.ts +24 -0
- package/dist/typed/index.d.ts.map +1 -0
- package/dist/typed/is.cjs +2 -2
- package/dist/typed/is.cjs.map +1 -1
- package/dist/typed/is.d.ts +95 -0
- package/dist/typed/is.d.ts.map +1 -0
- package/dist/typed/is.js +54 -42
- package/dist/typed/is.js.map +1 -1
- package/dist/typed/isArray.cjs +2 -2
- package/dist/typed/isArray.cjs.map +1 -1
- package/dist/typed/isArray.d.ts +16 -0
- package/dist/typed/isArray.d.ts.map +1 -0
- package/dist/typed/isArray.js +8 -8
- package/dist/typed/isArray.js.map +1 -1
- package/dist/typed/isBoolean.cjs +2 -2
- package/dist/typed/isBoolean.cjs.map +1 -1
- package/dist/typed/isBoolean.d.ts +23 -0
- package/dist/typed/isBoolean.d.ts.map +1 -0
- package/dist/typed/isBoolean.js +7 -6
- package/dist/typed/isBoolean.js.map +1 -1
- package/dist/typed/isDate.cjs +2 -2
- package/dist/typed/isDate.cjs.map +1 -1
- package/dist/typed/isDate.d.ts +16 -0
- package/dist/typed/isDate.d.ts.map +1 -0
- package/dist/typed/isDate.js +7 -8
- package/dist/typed/isDate.js.map +1 -1
- package/dist/typed/isDefined.cjs +2 -2
- package/dist/typed/isDefined.cjs.map +1 -1
- package/dist/typed/isDefined.d.ts +19 -0
- package/dist/typed/isDefined.d.ts.map +1 -0
- package/dist/typed/isDefined.js +7 -6
- package/dist/typed/isDefined.js.map +1 -1
- package/dist/typed/isEmpty.cjs +2 -2
- package/dist/typed/isEmpty.cjs.map +1 -1
- package/dist/typed/isEmpty.d.ts +24 -0
- package/dist/typed/isEmpty.d.ts.map +1 -0
- package/dist/typed/isEmpty.js +8 -9
- package/dist/typed/isEmpty.js.map +1 -1
- package/dist/typed/isEqual.cjs +2 -2
- package/dist/typed/isEqual.cjs.map +1 -1
- package/dist/typed/isEqual.d.ts +24 -0
- package/dist/typed/isEqual.d.ts.map +1 -0
- package/dist/typed/isEqual.js +27 -28
- package/dist/typed/isEqual.js.map +1 -1
- package/dist/typed/isEven.cjs +2 -2
- package/dist/typed/isEven.cjs.map +1 -1
- package/dist/typed/isEven.d.ts +9 -0
- package/dist/typed/isEven.d.ts.map +1 -0
- package/dist/typed/isEven.js +7 -6
- package/dist/typed/isEven.js.map +1 -1
- package/dist/typed/isFunction.cjs +2 -2
- package/dist/typed/isFunction.cjs.map +1 -1
- package/dist/typed/isFunction.d.ts +16 -0
- package/dist/typed/isFunction.d.ts.map +1 -0
- package/dist/typed/isFunction.js +7 -8
- package/dist/typed/isFunction.js.map +1 -1
- package/dist/typed/isMatch.cjs +2 -2
- package/dist/typed/isMatch.cjs.map +1 -1
- package/dist/typed/isMatch.d.ts +23 -0
- package/dist/typed/isMatch.d.ts.map +1 -0
- package/dist/typed/isMatch.js +16 -18
- package/dist/typed/isMatch.js.map +1 -1
- package/dist/typed/isNegative.cjs +2 -2
- package/dist/typed/isNegative.cjs.map +1 -1
- package/dist/typed/isNegative.d.ts +26 -0
- package/dist/typed/isNegative.d.ts.map +1 -0
- package/dist/typed/isNegative.js +7 -6
- package/dist/typed/isNegative.js.map +1 -1
- package/dist/typed/isNil.cjs +2 -2
- package/dist/typed/isNil.cjs.map +1 -1
- package/dist/typed/isNil.d.ts +17 -0
- package/dist/typed/isNil.d.ts.map +1 -0
- package/dist/typed/isNil.js +7 -8
- package/dist/typed/isNil.js.map +1 -1
- package/dist/typed/isNumber.cjs +2 -2
- package/dist/typed/isNumber.cjs.map +1 -1
- package/dist/typed/isNumber.d.ts +16 -0
- package/dist/typed/isNumber.d.ts.map +1 -0
- package/dist/typed/isNumber.js +8 -8
- package/dist/typed/isNumber.js.map +1 -1
- package/dist/typed/isObject.cjs +2 -2
- package/dist/typed/isObject.cjs.map +1 -1
- package/dist/typed/isObject.d.ts +19 -0
- package/dist/typed/isObject.d.ts.map +1 -0
- package/dist/typed/isObject.js +8 -8
- package/dist/typed/isObject.js.map +1 -1
- package/dist/typed/isOdd.cjs +2 -2
- package/dist/typed/isOdd.cjs.map +1 -1
- package/dist/typed/isOdd.d.ts +9 -0
- package/dist/typed/isOdd.d.ts.map +1 -0
- package/dist/typed/isOdd.js +7 -6
- package/dist/typed/isOdd.js.map +1 -1
- package/dist/typed/isPositive.cjs +2 -2
- package/dist/typed/isPositive.cjs.map +1 -1
- package/dist/typed/isPositive.d.ts +26 -0
- package/dist/typed/isPositive.d.ts.map +1 -0
- package/dist/typed/isPositive.js +7 -6
- package/dist/typed/isPositive.js.map +1 -1
- package/dist/typed/isPrimitive.cjs +2 -2
- package/dist/typed/isPrimitive.cjs.map +1 -1
- package/dist/typed/isPrimitive.d.ts +18 -0
- package/dist/typed/isPrimitive.d.ts.map +1 -0
- package/dist/typed/isPrimitive.js +8 -9
- package/dist/typed/isPrimitive.js.map +1 -1
- package/dist/typed/isPromise.cjs +2 -2
- package/dist/typed/isPromise.cjs.map +1 -1
- package/dist/typed/isPromise.d.ts +17 -0
- package/dist/typed/isPromise.d.ts.map +1 -0
- package/dist/typed/isPromise.js +7 -9
- package/dist/typed/isPromise.js.map +1 -1
- package/dist/typed/isRegex.cjs +2 -2
- package/dist/typed/isRegex.cjs.map +1 -1
- package/dist/typed/isRegex.d.ts +21 -0
- package/dist/typed/isRegex.d.ts.map +1 -0
- package/dist/typed/isRegex.js +7 -6
- package/dist/typed/isRegex.js.map +1 -1
- package/dist/typed/isString.cjs +2 -2
- package/dist/typed/isString.cjs.map +1 -1
- package/dist/typed/isString.d.ts +16 -0
- package/dist/typed/isString.d.ts.map +1 -0
- package/dist/typed/isString.js +8 -8
- package/dist/typed/isString.js.map +1 -1
- package/dist/typed/isWithin.cjs +2 -2
- package/dist/typed/isWithin.cjs.map +1 -1
- package/dist/typed/isWithin.d.ts +20 -0
- package/dist/typed/isWithin.d.ts.map +1 -0
- package/dist/typed/isWithin.js +9 -9
- package/dist/typed/isWithin.js.map +1 -1
- package/dist/typed/isZero.cjs +2 -2
- package/dist/typed/isZero.cjs.map +1 -1
- package/dist/typed/isZero.d.ts +25 -0
- package/dist/typed/isZero.d.ts.map +1 -0
- package/dist/typed/isZero.js +7 -6
- package/dist/typed/isZero.js.map +1 -1
- package/dist/typed/typeOf.cjs +2 -2
- package/dist/typed/typeOf.cjs.map +1 -1
- package/dist/typed/typeOf.d.ts +30 -0
- package/dist/typed/typeOf.d.ts.map +1 -0
- package/dist/typed/typeOf.js +11 -13
- package/dist/typed/typeOf.js.map +1 -1
- package/dist/types.d.ts +9 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +77 -12
- package/dist/array/aggregate.cjs +0 -2
- package/dist/array/aggregate.cjs.map +0 -1
- package/dist/array/aggregate.js +0 -16
- package/dist/array/aggregate.js.map +0 -1
- package/dist/array/alternate.cjs +0 -2
- package/dist/array/alternate.cjs.map +0 -1
- package/dist/array/alternate.js +0 -9
- package/dist/array/alternate.js.map +0 -1
- package/dist/array/arrange.cjs +0 -2
- package/dist/array/arrange.cjs.map +0 -1
- package/dist/array/arrange.js +0 -6
- package/dist/array/arrange.js.map +0 -1
- package/dist/array/compact.cjs +0 -2
- package/dist/array/compact.cjs.map +0 -1
- package/dist/array/compact.js +0 -9
- package/dist/array/compact.js.map +0 -1
- package/dist/array/every.cjs +0 -2
- package/dist/array/every.cjs.map +0 -1
- package/dist/array/every.js +0 -14
- package/dist/array/every.js.map +0 -1
- package/dist/array/filter.cjs +0 -2
- package/dist/array/filter.cjs.map +0 -1
- package/dist/array/filter.js +0 -14
- package/dist/array/filter.js.map +0 -1
- package/dist/array/find.cjs +0 -2
- package/dist/array/find.cjs.map +0 -1
- package/dist/array/find.js +0 -14
- package/dist/array/find.js.map +0 -1
- package/dist/array/findIndex.cjs +0 -2
- package/dist/array/findIndex.cjs.map +0 -1
- package/dist/array/findIndex.js +0 -14
- package/dist/array/findIndex.js.map +0 -1
- package/dist/array/findLast.cjs +0 -2
- package/dist/array/findLast.cjs.map +0 -1
- package/dist/array/findLast.js +0 -14
- package/dist/array/findLast.js.map +0 -1
- package/dist/array/flatten.cjs +0 -2
- package/dist/array/flatten.cjs.map +0 -1
- package/dist/array/flatten.js +0 -7
- package/dist/array/flatten.js.map +0 -1
- package/dist/array/map.cjs +0 -2
- package/dist/array/map.cjs.map +0 -1
- package/dist/array/map.js +0 -18
- package/dist/array/map.js.map +0 -1
- package/dist/array/reduce.cjs +0 -2
- package/dist/array/reduce.cjs.map +0 -1
- package/dist/array/reduce.js +0 -16
- package/dist/array/reduce.js.map +0 -1
- package/dist/array/shift.cjs +0 -2
- package/dist/array/shift.cjs.map +0 -1
- package/dist/array/shift.js +0 -13
- package/dist/array/shift.js.map +0 -1
- package/dist/array/some.cjs +0 -2
- package/dist/array/some.cjs.map +0 -1
- package/dist/array/some.js +0 -14
- package/dist/array/some.js.map +0 -1
- package/dist/array/substitute.cjs +0 -2
- package/dist/array/substitute.cjs.map +0 -1
- package/dist/array/substitute.js +0 -13
- package/dist/array/substitute.js.map +0 -1
- package/dist/async/delay.cjs +0 -2
- package/dist/async/delay.cjs.map +0 -1
- package/dist/async/delay.js +0 -8
- package/dist/async/delay.js.map +0 -1
- package/dist/function/proxy.cjs +0 -2
- package/dist/function/proxy.cjs.map +0 -1
- package/dist/function/proxy.js +0 -22
- package/dist/function/proxy.js.map +0 -1
- package/dist/function/prune.cjs +0 -2
- package/dist/function/prune.cjs.map +0 -1
- package/dist/function/prune.js +0 -30
- package/dist/function/prune.js.map +0 -1
- package/dist/function/worker.cjs +0 -14
- package/dist/function/worker.cjs.map +0 -1
- package/dist/function/worker.js +0 -29
- package/dist/function/worker.js.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/logit/dist/logit.cjs +0 -2
- package/dist/logit/dist/logit.cjs.map +0 -1
- package/dist/logit/dist/logit.js +0 -263
- package/dist/logit/dist/logit.js.map +0 -1
- package/dist/math/add.cjs +0 -2
- package/dist/math/add.cjs.map +0 -1
- package/dist/math/add.js +0 -9
- package/dist/math/add.js.map +0 -1
- package/dist/math/boil.cjs +0 -2
- package/dist/math/boil.cjs.map +0 -1
- package/dist/math/boil.js +0 -17
- package/dist/math/boil.js.map +0 -1
- package/dist/math/divide.cjs +0 -2
- package/dist/math/divide.cjs.map +0 -1
- package/dist/math/divide.js +0 -11
- package/dist/math/divide.js.map +0 -1
- package/dist/math/multiply.cjs +0 -2
- package/dist/math/multiply.cjs.map +0 -1
- package/dist/math/multiply.js +0 -9
- package/dist/math/multiply.js.map +0 -1
- package/dist/math/rate.cjs +0 -2
- package/dist/math/rate.cjs.map +0 -1
- package/dist/math/rate.js +0 -9
- package/dist/math/rate.js.map +0 -1
- package/dist/math/subtract.cjs +0 -2
- package/dist/math/subtract.cjs.map +0 -1
- package/dist/math/subtract.js +0 -9
- package/dist/math/subtract.js.map +0 -1
- package/dist/object/cache.cjs +0 -2
- package/dist/object/cache.cjs.map +0 -1
- package/dist/object/cache.js +0 -63
- package/dist/object/cache.js.map +0 -1
- package/dist/object/clone.cjs +0 -2
- package/dist/object/clone.cjs.map +0 -1
- package/dist/object/clone.js +0 -17
- package/dist/object/clone.js.map +0 -1
- package/dist/object/entries.cjs +0 -2
- package/dist/object/entries.cjs.map +0 -1
- package/dist/object/entries.js +0 -9
- package/dist/object/entries.js.map +0 -1
- package/dist/object/keys.cjs +0 -2
- package/dist/object/keys.cjs.map +0 -1
- package/dist/object/keys.js +0 -9
- package/dist/object/keys.js.map +0 -1
- package/dist/object/values.cjs +0 -2
- package/dist/object/values.cjs.map +0 -1
- package/dist/object/values.js +0 -9
- package/dist/object/values.js.map +0 -1
- package/dist/typed/ge.cjs +0 -2
- package/dist/typed/ge.cjs.map +0 -1
- package/dist/typed/ge.js +0 -7
- package/dist/typed/ge.js.map +0 -1
- package/dist/typed/gt.cjs +0 -2
- package/dist/typed/gt.cjs.map +0 -1
- package/dist/typed/gt.js +0 -7
- package/dist/typed/gt.js.map +0 -1
- package/dist/typed/le.cjs +0 -2
- package/dist/typed/le.cjs.map +0 -1
- package/dist/typed/le.js +0 -7
- package/dist/typed/le.js.map +0 -1
- package/dist/typed/lt.cjs +0 -2
- package/dist/typed/lt.cjs.map +0 -1
- package/dist/typed/lt.js +0 -7
- package/dist/typed/lt.js.map +0 -1
package/dist/async/attempt.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=attempt.cjs.map
|
|
1
|
+
const e=require(`./predict.cjs`),t=require(`./retry.cjs`);async function n(n,{onError:r,timeout:i=7e3,times:a=3}={}){try{return{ok:!0,value:await t.retry(()=>e.predict(()=>n(),{timeout:i}),{times:a})}}catch(e){return r?.(e),{error:e,ok:!1}}}exports.attempt=n;
|
|
2
|
+
//# sourceMappingURL=attempt.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attempt.cjs","sources":["../../src/async/attempt.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"attempt.cjs","names":[],"sources":["../../src/async/attempt.ts"],"sourcesContent":["import type { Fn } from '../types';\n\nimport { predict } from './predict';\nimport { retry } from './retry';\n\ntype AttemptOptions = {\n onError?: (err: unknown) => void;\n timeout?: number;\n times?: number;\n};\n\nexport type AttemptResult<R> = { ok: true; value: R } | { error: unknown; ok: false };\n\n/**\n * Attempts to execute a function with retry logic and an optional timeout.\n * Returns a discriminated union so callers can handle success and failure\n * explicitly without relying on `undefined`.\n *\n * @example\n * ```ts\n * const result = await attempt(fetchUser, { times: 3, timeout: 5000 });\n *\n * if (result.ok) {\n * console.log(result.value);\n * } else {\n * console.error(result.error);\n * }\n * ```\n *\n * @param fn - The function to be executed.\n * @param [options] - Configuration options.\n * @param [options.times=3] - Total number of attempts (including the first).\n * @param [options.onError] - Called with the error when all attempts fail.\n * @param [options.timeout=7000] - Per-attempt timeout in milliseconds.\n *\n * @returns `{ ok: true, value }` on success or `{ ok: false, error }` on failure.\n */\nexport async function attempt<T extends Fn, R = Awaited<ReturnType<T>>>(\n fn: T,\n { onError, timeout = 7000, times = 3 }: AttemptOptions = {},\n): Promise<AttemptResult<R>> {\n try {\n const value = await retry(() => predict<R>(() => fn(), { timeout }), { times });\n\n return { ok: true, value };\n } catch (err) {\n onError?.(err);\n\n return { error: err, ok: false };\n }\n}\n"],"mappings":"0DAqCA,eAAsB,EACpB,EACA,CAAE,UAAS,UAAU,IAAM,QAAQ,GAAsB,EAAE,CAChC,CAC3B,GAAI,CAGF,MAAO,CAAE,GAAI,GAAM,MAFL,MAAM,EAAA,UAAY,EAAA,YAAiB,GAAI,CAAE,CAAE,UAAS,CAAC,CAAE,CAAE,QAAO,CAAC,CAErD,OACnB,EAAK,CAGZ,OAFA,IAAU,EAAI,CAEP,CAAE,MAAO,EAAK,GAAI,GAAO"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Fn } from '../types';
|
|
2
|
+
type AttemptOptions = {
|
|
3
|
+
onError?: (err: unknown) => void;
|
|
4
|
+
timeout?: number;
|
|
5
|
+
times?: number;
|
|
6
|
+
};
|
|
7
|
+
export type AttemptResult<R> = {
|
|
8
|
+
ok: true;
|
|
9
|
+
value: R;
|
|
10
|
+
} | {
|
|
11
|
+
error: unknown;
|
|
12
|
+
ok: false;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Attempts to execute a function with retry logic and an optional timeout.
|
|
16
|
+
* Returns a discriminated union so callers can handle success and failure
|
|
17
|
+
* explicitly without relying on `undefined`.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const result = await attempt(fetchUser, { times: 3, timeout: 5000 });
|
|
22
|
+
*
|
|
23
|
+
* if (result.ok) {
|
|
24
|
+
* console.log(result.value);
|
|
25
|
+
* } else {
|
|
26
|
+
* console.error(result.error);
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @param fn - The function to be executed.
|
|
31
|
+
* @param [options] - Configuration options.
|
|
32
|
+
* @param [options.times=3] - Total number of attempts (including the first).
|
|
33
|
+
* @param [options.onError] - Called with the error when all attempts fail.
|
|
34
|
+
* @param [options.timeout=7000] - Per-attempt timeout in milliseconds.
|
|
35
|
+
*
|
|
36
|
+
* @returns `{ ok: true, value }` on success or `{ ok: false, error }` on failure.
|
|
37
|
+
*/
|
|
38
|
+
export declare function attempt<T extends Fn, R = Awaited<ReturnType<T>>>(fn: T, { onError, timeout, times }?: AttemptOptions): Promise<AttemptResult<R>>;
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=attempt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attempt.d.ts","sourceRoot":"","sources":["../../src/async/attempt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,UAAU,CAAC;AAKnC,KAAK,cAAc,GAAG;IACpB,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,CAAC;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,EAAE,EAAE,KAAK,CAAA;CAAE,CAAC;AAEtF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAsB,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EACpE,EAAE,EAAE,CAAC,EACL,EAAE,OAAO,EAAE,OAAc,EAAE,KAAS,EAAE,GAAE,cAAmB,GAC1D,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAU3B"}
|
package/dist/async/attempt.js
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
async function
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { predict as e } from "./predict.js";
|
|
2
|
+
import { retry as t } from "./retry.js";
|
|
3
|
+
//#region src/async/attempt.ts
|
|
4
|
+
async function n(n, { onError: r, timeout: i = 7e3, times: a = 3 } = {}) {
|
|
5
|
+
try {
|
|
6
|
+
return {
|
|
7
|
+
ok: !0,
|
|
8
|
+
value: await t(() => e(() => n(), { timeout: i }), { times: a })
|
|
9
|
+
};
|
|
10
|
+
} catch (e) {
|
|
11
|
+
return r?.(e), {
|
|
12
|
+
error: e,
|
|
13
|
+
ok: !1
|
|
14
|
+
};
|
|
15
|
+
}
|
|
11
16
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
//# sourceMappingURL=attempt.js.map
|
|
17
|
+
//#endregion
|
|
18
|
+
export { n as attempt };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=attempt.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attempt.js","sources":["../../src/async/attempt.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"attempt.js","names":[],"sources":["../../src/async/attempt.ts"],"sourcesContent":["import type { Fn } from '../types';\n\nimport { predict } from './predict';\nimport { retry } from './retry';\n\ntype AttemptOptions = {\n onError?: (err: unknown) => void;\n timeout?: number;\n times?: number;\n};\n\nexport type AttemptResult<R> = { ok: true; value: R } | { error: unknown; ok: false };\n\n/**\n * Attempts to execute a function with retry logic and an optional timeout.\n * Returns a discriminated union so callers can handle success and failure\n * explicitly without relying on `undefined`.\n *\n * @example\n * ```ts\n * const result = await attempt(fetchUser, { times: 3, timeout: 5000 });\n *\n * if (result.ok) {\n * console.log(result.value);\n * } else {\n * console.error(result.error);\n * }\n * ```\n *\n * @param fn - The function to be executed.\n * @param [options] - Configuration options.\n * @param [options.times=3] - Total number of attempts (including the first).\n * @param [options.onError] - Called with the error when all attempts fail.\n * @param [options.timeout=7000] - Per-attempt timeout in milliseconds.\n *\n * @returns `{ ok: true, value }` on success or `{ ok: false, error }` on failure.\n */\nexport async function attempt<T extends Fn, R = Awaited<ReturnType<T>>>(\n fn: T,\n { onError, timeout = 7000, times = 3 }: AttemptOptions = {},\n): Promise<AttemptResult<R>> {\n try {\n const value = await retry(() => predict<R>(() => fn(), { timeout }), { times });\n\n return { ok: true, value };\n } catch (err) {\n onError?.(err);\n\n return { error: err, ok: false };\n }\n}\n"],"mappings":";;;AAqCA,eAAsB,EACpB,GACA,EAAE,YAAS,aAAU,KAAM,WAAQ,MAAsB,EAAE,EAChC;AAC3B,KAAI;AAGF,SAAO;GAAE,IAAI;GAAM,OAFL,MAAM,QAAY,QAAiB,GAAI,EAAE,EAAE,YAAS,CAAC,EAAE,EAAE,UAAO,CAAC;GAErD;UACnB,GAAK;AAGZ,SAFA,IAAU,EAAI,EAEP;GAAE,OAAO;GAAK,IAAI;GAAO"}
|
package/dist/async/defer.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=defer.cjs.map
|
|
1
|
+
function e(){let{promise:e,reject:t,resolve:n}=Promise.withResolvers();return{promise:e,reject:t,resolve:n}}exports.defer=e;
|
|
2
|
+
//# sourceMappingURL=defer.cjs.map
|
package/dist/async/defer.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defer.cjs","sources":["../../src/async/defer.ts"],"sourcesContent":["/**\n * Creates a deferred promise with resolve and reject methods exposed.\n * Useful for creating promises that are resolved/rejected externally.\n *\n * @example\n * ```ts\n * const deferred = defer<string>();\n *\n * setTimeout(() => {\n * deferred.resolve('Done!');\n * }, 1000);\n *\n * const result = await deferred.promise; // 'Done!'\n * ```\n *\n * @returns Object with promise and resolve/reject methods\n */\nexport function defer<T = void>(): {\n promise: Promise<T>;\n
|
|
1
|
+
{"version":3,"file":"defer.cjs","names":[],"sources":["../../src/async/defer.ts"],"sourcesContent":["/**\n * Creates a deferred promise with resolve and reject methods exposed.\n * Useful for creating promises that are resolved/rejected externally.\n *\n * @example\n * ```ts\n * const deferred = defer<string>();\n *\n * setTimeout(() => {\n * deferred.resolve('Done!');\n * }, 1000);\n *\n * const result = await deferred.promise; // 'Done!'\n * ```\n *\n * @returns Object with promise and resolve/reject methods\n */\nexport function defer<T = void>(): {\n promise: Promise<T>;\n reject: (reason?: unknown) => void;\n resolve: (value: T | PromiseLike<T>) => void;\n} {\n const { promise, reject, resolve } = Promise.withResolvers<T>();\n\n return { promise, reject, resolve };\n}\n"],"mappings":"AAiBA,SAAgB,GAId,CACA,GAAM,CAAE,UAAS,SAAQ,WAAY,QAAQ,eAAkB,CAE/D,MAAO,CAAE,UAAS,SAAQ,UAAS"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a deferred promise with resolve and reject methods exposed.
|
|
3
|
+
* Useful for creating promises that are resolved/rejected externally.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* const deferred = defer<string>();
|
|
8
|
+
*
|
|
9
|
+
* setTimeout(() => {
|
|
10
|
+
* deferred.resolve('Done!');
|
|
11
|
+
* }, 1000);
|
|
12
|
+
*
|
|
13
|
+
* const result = await deferred.promise; // 'Done!'
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @returns Object with promise and resolve/reject methods
|
|
17
|
+
*/
|
|
18
|
+
export declare function defer<T = void>(): {
|
|
19
|
+
promise: Promise<T>;
|
|
20
|
+
reject: (reason?: unknown) => void;
|
|
21
|
+
resolve: (value: T | PromiseLike<T>) => void;
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=defer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defer.d.ts","sourceRoot":"","sources":["../../src/async/defer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,KAAK,CAAC,CAAC,GAAG,IAAI,KAAK;IACjC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACpB,MAAM,EAAE,CAAC,MAAM,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IACnC,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;CAC9C,CAIA"}
|
package/dist/async/defer.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
//#region src/async/defer.ts
|
|
2
|
+
function e() {
|
|
3
|
+
let { promise: e, reject: t, resolve: n } = Promise.withResolvers();
|
|
4
|
+
return {
|
|
5
|
+
promise: e,
|
|
6
|
+
reject: t,
|
|
7
|
+
resolve: n
|
|
8
|
+
};
|
|
6
9
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
//# sourceMappingURL=defer.js.map
|
|
10
|
+
//#endregion
|
|
11
|
+
export { e as defer };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=defer.js.map
|
package/dist/async/defer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defer.js","sources":["../../src/async/defer.ts"],"sourcesContent":["/**\n * Creates a deferred promise with resolve and reject methods exposed.\n * Useful for creating promises that are resolved/rejected externally.\n *\n * @example\n * ```ts\n * const deferred = defer<string>();\n *\n * setTimeout(() => {\n * deferred.resolve('Done!');\n * }, 1000);\n *\n * const result = await deferred.promise; // 'Done!'\n * ```\n *\n * @returns Object with promise and resolve/reject methods\n */\nexport function defer<T = void>(): {\n promise: Promise<T>;\n
|
|
1
|
+
{"version":3,"file":"defer.js","names":[],"sources":["../../src/async/defer.ts"],"sourcesContent":["/**\n * Creates a deferred promise with resolve and reject methods exposed.\n * Useful for creating promises that are resolved/rejected externally.\n *\n * @example\n * ```ts\n * const deferred = defer<string>();\n *\n * setTimeout(() => {\n * deferred.resolve('Done!');\n * }, 1000);\n *\n * const result = await deferred.promise; // 'Done!'\n * ```\n *\n * @returns Object with promise and resolve/reject methods\n */\nexport function defer<T = void>(): {\n promise: Promise<T>;\n reject: (reason?: unknown) => void;\n resolve: (value: T | PromiseLike<T>) => void;\n} {\n const { promise, reject, resolve } = Promise.withResolvers<T>();\n\n return { promise, reject, resolve };\n}\n"],"mappings":";AAiBA,SAAgB,IAId;CACA,IAAM,EAAE,YAAS,WAAQ,eAAY,QAAQ,eAAkB;AAE/D,QAAO;EAAE;EAAS;EAAQ;EAAS"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './attempt';
|
|
2
|
+
export * from './defer';
|
|
3
|
+
export * from './parallel';
|
|
4
|
+
export * from './pool';
|
|
5
|
+
export * from './predict';
|
|
6
|
+
export * from './queue';
|
|
7
|
+
export * from './race';
|
|
8
|
+
export * from './retry';
|
|
9
|
+
export * from './scheduler';
|
|
10
|
+
export * from './sleep';
|
|
11
|
+
export * from './waitFor';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/async/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC"}
|
package/dist/async/parallel.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=parallel.cjs.map
|
|
1
|
+
async function e(e,t,n,r){if(e<1)throw Error(`Limit must be at least 1`);if(r?.aborted)throw new DOMException(`Aborted`,`AbortError`);let i=Array(t.length),a=0,o=!1,s,c=async()=>{for(;a<t.length&&!o;){if(r?.aborted){o=!0,s=new DOMException(`Aborted`,`AbortError`);break}let e=a++;try{i[e]=await n(t[e],e,t)}catch(e){o=!0,s=e;break}}},l=[],u=Math.min(e,t.length);for(let e=0;e<u;e++)l.push(c());if(await Promise.all(l),o)throw s;return i}exports.parallel=e;
|
|
2
|
+
//# sourceMappingURL=parallel.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parallel.cjs","sources":["../../src/async/parallel.ts"],"sourcesContent":["/**\n * Processes an array with an async callback with controlled parallelism.\n * Similar to Promise.all, but limits how many items are processed concurrently.\n * Returns an ordered array of results.\n *\n * @example\n * ```ts\n * // Process 3 items at a time\n * const results = await parallel(3, [1, 2, 3, 4, 5], async (n) => {\n * await delay(100);\n * return n * 2;\n * });\n * // [2, 4, 6, 8, 10]\n *\n * // With abort signal\n * const controller = new AbortController();\n * const results = await parallel(2, items, async (item) => {\n * return processItem(item);\n * }, controller.signal);\n * ```\n *\n * @param limit - Maximum number of concurrent operations (must be >= 1)\n * @param array - Array of items to process\n * @param callback - Async function to process each item\n * @param signal - Optional AbortSignal to cancel processing\n * @returns Promise resolving to an ordered array of results\n * @throws {Error} If limit is less than 1\n * @throws {DOMException} If aborted via signal\n */\nexport async function parallel<T, R>(\n limit: number,\n array: T[],\n callback: (item: T, index: number, array: T[]) => Promise<R>,\n signal?: AbortSignal,\n): Promise<R[]> {\n if (limit < 1) {\n throw new Error('Limit must be at least 1');\n }\n\n if (signal?.aborted) {\n throw new DOMException('Aborted', 'AbortError');\n }\n\n const results: R[] = new Array(array.length);\n let currentIndex = 0;\n let hasError = false;\n let error: unknown;\n\n
|
|
1
|
+
{"version":3,"file":"parallel.cjs","names":[],"sources":["../../src/async/parallel.ts"],"sourcesContent":["/**\n * Processes an array with an async callback with controlled parallelism.\n * Similar to Promise.all, but limits how many items are processed concurrently.\n * Returns an ordered array of results.\n *\n * @example\n * ```ts\n * // Process 3 items at a time\n * const results = await parallel(3, [1, 2, 3, 4, 5], async (n) => {\n * await delay(100);\n * return n * 2;\n * });\n * // [2, 4, 6, 8, 10]\n *\n * // With abort signal\n * const controller = new AbortController();\n * const results = await parallel(2, items, async (item) => {\n * return processItem(item);\n * }, controller.signal);\n * ```\n *\n * @param limit - Maximum number of concurrent operations (must be >= 1)\n * @param array - Array of items to process\n * @param callback - Async function to process each item\n * @param signal - Optional AbortSignal to cancel processing\n * @returns Promise resolving to an ordered array of results\n * @throws {Error} If limit is less than 1\n * @throws {DOMException} If aborted via signal\n */\nexport async function parallel<T, R>(\n limit: number,\n array: T[],\n callback: (item: T, index: number, array: T[]) => Promise<R>,\n signal?: AbortSignal,\n): Promise<R[]> {\n if (limit < 1) {\n throw new Error('Limit must be at least 1');\n }\n\n if (signal?.aborted) {\n throw new DOMException('Aborted', 'AbortError');\n }\n\n const results: R[] = new Array(array.length);\n let currentIndex = 0;\n let hasError = false;\n let error: unknown;\n\n const worker = async (): Promise<void> => {\n while (currentIndex < array.length && !hasError) {\n if (signal?.aborted) {\n hasError = true;\n error = new DOMException('Aborted', 'AbortError');\n break;\n }\n\n const index = currentIndex++;\n\n try {\n results[index] = await callback(array[index], index, array);\n } catch (err) {\n hasError = true;\n error = err;\n break;\n }\n }\n };\n\n // Create workers up to the limit\n const workers: Promise<void>[] = [];\n const workerCount = Math.min(limit, array.length);\n\n for (let i = 0; i < workerCount; i++) {\n workers.push(worker());\n }\n\n // Wait for all workers to complete\n await Promise.all(workers);\n\n // If there was an error, throw it\n if (hasError) {\n throw error;\n }\n\n return results;\n}\n"],"mappings":"AA6BA,eAAsB,EACpB,EACA,EACA,EACA,EACc,CACd,GAAI,EAAQ,EACV,MAAU,MAAM,2BAA2B,CAG7C,GAAI,GAAQ,QACV,MAAM,IAAI,aAAa,UAAW,aAAa,CAGjD,IAAM,EAAmB,MAAM,EAAM,OAAO,CACxC,EAAe,EACf,EAAW,GACX,EAEE,EAAS,SAA2B,CACxC,KAAO,EAAe,EAAM,QAAU,CAAC,GAAU,CAC/C,GAAI,GAAQ,QAAS,CACnB,EAAW,GACX,EAAQ,IAAI,aAAa,UAAW,aAAa,CACjD,MAGF,IAAM,EAAQ,IAEd,GAAI,CACF,EAAQ,GAAS,MAAM,EAAS,EAAM,GAAQ,EAAO,EAAM,OACpD,EAAK,CACZ,EAAW,GACX,EAAQ,EACR,SAMA,EAA2B,EAAE,CAC7B,EAAc,KAAK,IAAI,EAAO,EAAM,OAAO,CAEjD,IAAK,IAAI,EAAI,EAAG,EAAI,EAAa,IAC/B,EAAQ,KAAK,GAAQ,CAAC,CAOxB,GAHA,MAAM,QAAQ,IAAI,EAAQ,CAGtB,EACF,MAAM,EAGR,OAAO"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Processes an array with an async callback with controlled parallelism.
|
|
3
|
+
* Similar to Promise.all, but limits how many items are processed concurrently.
|
|
4
|
+
* Returns an ordered array of results.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* // Process 3 items at a time
|
|
9
|
+
* const results = await parallel(3, [1, 2, 3, 4, 5], async (n) => {
|
|
10
|
+
* await delay(100);
|
|
11
|
+
* return n * 2;
|
|
12
|
+
* });
|
|
13
|
+
* // [2, 4, 6, 8, 10]
|
|
14
|
+
*
|
|
15
|
+
* // With abort signal
|
|
16
|
+
* const controller = new AbortController();
|
|
17
|
+
* const results = await parallel(2, items, async (item) => {
|
|
18
|
+
* return processItem(item);
|
|
19
|
+
* }, controller.signal);
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @param limit - Maximum number of concurrent operations (must be >= 1)
|
|
23
|
+
* @param array - Array of items to process
|
|
24
|
+
* @param callback - Async function to process each item
|
|
25
|
+
* @param signal - Optional AbortSignal to cancel processing
|
|
26
|
+
* @returns Promise resolving to an ordered array of results
|
|
27
|
+
* @throws {Error} If limit is less than 1
|
|
28
|
+
* @throws {DOMException} If aborted via signal
|
|
29
|
+
*/
|
|
30
|
+
export declare function parallel<T, R>(limit: number, array: T[], callback: (item: T, index: number, array: T[]) => Promise<R>, signal?: AbortSignal): Promise<R[]>;
|
|
31
|
+
//# sourceMappingURL=parallel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parallel.d.ts","sourceRoot":"","sources":["../../src/async/parallel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAsB,QAAQ,CAAC,CAAC,EAAE,CAAC,EACjC,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,CAAC,EAAE,EACV,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,OAAO,CAAC,CAAC,CAAC,EAC5D,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,CAAC,EAAE,CAAC,CAmDd"}
|
package/dist/async/parallel.js
CHANGED
|
@@ -1,28 +1,27 @@
|
|
|
1
|
-
async
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return c;
|
|
1
|
+
//#region src/async/parallel.ts
|
|
2
|
+
async function e(e, t, n, r) {
|
|
3
|
+
if (e < 1) throw Error("Limit must be at least 1");
|
|
4
|
+
if (r?.aborted) throw new DOMException("Aborted", "AbortError");
|
|
5
|
+
let i = Array(t.length), a = 0, o = !1, s, c = async () => {
|
|
6
|
+
for (; a < t.length && !o;) {
|
|
7
|
+
if (r?.aborted) {
|
|
8
|
+
o = !0, s = new DOMException("Aborted", "AbortError");
|
|
9
|
+
break;
|
|
10
|
+
}
|
|
11
|
+
let e = a++;
|
|
12
|
+
try {
|
|
13
|
+
i[e] = await n(t[e], e, t);
|
|
14
|
+
} catch (e) {
|
|
15
|
+
o = !0, s = e;
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}, l = [], u = Math.min(e, t.length);
|
|
20
|
+
for (let e = 0; e < u; e++) l.push(c());
|
|
21
|
+
if (await Promise.all(l), o) throw s;
|
|
22
|
+
return i;
|
|
24
23
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
//# sourceMappingURL=parallel.js.map
|
|
24
|
+
//#endregion
|
|
25
|
+
export { e as parallel };
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=parallel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parallel.js","sources":["../../src/async/parallel.ts"],"sourcesContent":["/**\n * Processes an array with an async callback with controlled parallelism.\n * Similar to Promise.all, but limits how many items are processed concurrently.\n * Returns an ordered array of results.\n *\n * @example\n * ```ts\n * // Process 3 items at a time\n * const results = await parallel(3, [1, 2, 3, 4, 5], async (n) => {\n * await delay(100);\n * return n * 2;\n * });\n * // [2, 4, 6, 8, 10]\n *\n * // With abort signal\n * const controller = new AbortController();\n * const results = await parallel(2, items, async (item) => {\n * return processItem(item);\n * }, controller.signal);\n * ```\n *\n * @param limit - Maximum number of concurrent operations (must be >= 1)\n * @param array - Array of items to process\n * @param callback - Async function to process each item\n * @param signal - Optional AbortSignal to cancel processing\n * @returns Promise resolving to an ordered array of results\n * @throws {Error} If limit is less than 1\n * @throws {DOMException} If aborted via signal\n */\nexport async function parallel<T, R>(\n limit: number,\n array: T[],\n callback: (item: T, index: number, array: T[]) => Promise<R>,\n signal?: AbortSignal,\n): Promise<R[]> {\n if (limit < 1) {\n throw new Error('Limit must be at least 1');\n }\n\n if (signal?.aborted) {\n throw new DOMException('Aborted', 'AbortError');\n }\n\n const results: R[] = new Array(array.length);\n let currentIndex = 0;\n let hasError = false;\n let error: unknown;\n\n
|
|
1
|
+
{"version":3,"file":"parallel.js","names":[],"sources":["../../src/async/parallel.ts"],"sourcesContent":["/**\n * Processes an array with an async callback with controlled parallelism.\n * Similar to Promise.all, but limits how many items are processed concurrently.\n * Returns an ordered array of results.\n *\n * @example\n * ```ts\n * // Process 3 items at a time\n * const results = await parallel(3, [1, 2, 3, 4, 5], async (n) => {\n * await delay(100);\n * return n * 2;\n * });\n * // [2, 4, 6, 8, 10]\n *\n * // With abort signal\n * const controller = new AbortController();\n * const results = await parallel(2, items, async (item) => {\n * return processItem(item);\n * }, controller.signal);\n * ```\n *\n * @param limit - Maximum number of concurrent operations (must be >= 1)\n * @param array - Array of items to process\n * @param callback - Async function to process each item\n * @param signal - Optional AbortSignal to cancel processing\n * @returns Promise resolving to an ordered array of results\n * @throws {Error} If limit is less than 1\n * @throws {DOMException} If aborted via signal\n */\nexport async function parallel<T, R>(\n limit: number,\n array: T[],\n callback: (item: T, index: number, array: T[]) => Promise<R>,\n signal?: AbortSignal,\n): Promise<R[]> {\n if (limit < 1) {\n throw new Error('Limit must be at least 1');\n }\n\n if (signal?.aborted) {\n throw new DOMException('Aborted', 'AbortError');\n }\n\n const results: R[] = new Array(array.length);\n let currentIndex = 0;\n let hasError = false;\n let error: unknown;\n\n const worker = async (): Promise<void> => {\n while (currentIndex < array.length && !hasError) {\n if (signal?.aborted) {\n hasError = true;\n error = new DOMException('Aborted', 'AbortError');\n break;\n }\n\n const index = currentIndex++;\n\n try {\n results[index] = await callback(array[index], index, array);\n } catch (err) {\n hasError = true;\n error = err;\n break;\n }\n }\n };\n\n // Create workers up to the limit\n const workers: Promise<void>[] = [];\n const workerCount = Math.min(limit, array.length);\n\n for (let i = 0; i < workerCount; i++) {\n workers.push(worker());\n }\n\n // Wait for all workers to complete\n await Promise.all(workers);\n\n // If there was an error, throw it\n if (hasError) {\n throw error;\n }\n\n return results;\n}\n"],"mappings":";AA6BA,eAAsB,EACpB,GACA,GACA,GACA,GACc;AACd,KAAI,IAAQ,EACV,OAAU,MAAM,2BAA2B;AAG7C,KAAI,GAAQ,QACV,OAAM,IAAI,aAAa,WAAW,aAAa;CAGjD,IAAM,IAAmB,MAAM,EAAM,OAAO,EACxC,IAAe,GACf,IAAW,IACX,GAEE,IAAS,YAA2B;AACxC,SAAO,IAAe,EAAM,UAAU,CAAC,IAAU;AAC/C,OAAI,GAAQ,SAAS;AAEnB,IADA,IAAW,IACX,IAAQ,IAAI,aAAa,WAAW,aAAa;AACjD;;GAGF,IAAM,IAAQ;AAEd,OAAI;AACF,MAAQ,KAAS,MAAM,EAAS,EAAM,IAAQ,GAAO,EAAM;YACpD,GAAK;AAEZ,IADA,IAAW,IACX,IAAQ;AACR;;;IAMA,IAA2B,EAAE,EAC7B,IAAc,KAAK,IAAI,GAAO,EAAM,OAAO;AAEjD,MAAK,IAAI,IAAI,GAAG,IAAI,GAAa,IAC/B,GAAQ,KAAK,GAAQ,CAAC;AAOxB,KAHA,MAAM,QAAQ,IAAI,EAAQ,EAGtB,EACF,OAAM;AAGR,QAAO"}
|
package/dist/async/pool.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=pool.cjs.map
|
|
1
|
+
const e=require(`../function/assert.cjs`);function t(t){e.assert(t>=1,`Pool limit must be at least 1`,{args:{limit:t},type:RangeError});let n=0,r=[],i=()=>{r.length>0&&n<t&&r.shift()?.()};return async e=>{for(;n>=t;)await new Promise(e=>r.push(e));n++;try{return await e()}finally{n--,i()}}}exports.pool=t;
|
|
2
|
+
//# sourceMappingURL=pool.cjs.map
|
package/dist/async/pool.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pool.cjs","sources":["../../src/async/pool.ts"],"sourcesContent":["import { assert } from '../function/assert';\n\n/**\n * Creates a promise pool that limits the number of concurrent promises.\n * Useful for rate limiting API calls or controlling resource usage.\n *\n * @example\n * ```ts\n * const requestPool = pool(3);\n *\n * const results = await Promise.all([\n * requestPool(() => fetch('/api/1')),\n * requestPool(() => fetch('/api/2')),\n * requestPool(() => fetch('/api/3')),\n * requestPool(() => fetch('/api/4')), // Will wait for one of the above to finish\n * ]);\n * ```\n *\n * @param limit - Maximum number of concurrent promises\n * @returns Function that accepts a promise-returning function and executes it when a slot is available\n */\nexport function pool(limit: number): <T>(fn: () => Promise<T>) => Promise<T> {\n assert(limit >= 1, 'Pool limit must be at least 1', { args: { limit }, type: RangeError });\n\n let activeCount = 0;\n const queue: Array<() => void> = [];\n\n const dequeue = (): void => {\n if (queue.length > 0 && activeCount < limit) {\n const next = queue.shift();\n next?.();\n }\n };\n\n return async <T>(fn: () => Promise<T>): Promise<T> => {\n while (activeCount >= limit) {\n await new Promise<void>((resolve) => queue.push(resolve));\n }\n\n activeCount++;\n\n try {\n return await fn();\n } finally {\n activeCount--;\n dequeue();\n }\n };\n}\n"],"
|
|
1
|
+
{"version":3,"file":"pool.cjs","names":[],"sources":["../../src/async/pool.ts"],"sourcesContent":["import { assert } from '../function/assert';\n\n/**\n * Creates a promise pool that limits the number of concurrent promises.\n * Useful for rate limiting API calls or controlling resource usage.\n *\n * @example\n * ```ts\n * const requestPool = pool(3);\n *\n * const results = await Promise.all([\n * requestPool(() => fetch('/api/1')),\n * requestPool(() => fetch('/api/2')),\n * requestPool(() => fetch('/api/3')),\n * requestPool(() => fetch('/api/4')), // Will wait for one of the above to finish\n * ]);\n * ```\n *\n * @param limit - Maximum number of concurrent promises\n * @returns Function that accepts a promise-returning function and executes it when a slot is available\n */\nexport function pool(limit: number): <T>(fn: () => Promise<T>) => Promise<T> {\n assert(limit >= 1, 'Pool limit must be at least 1', { args: { limit }, type: RangeError });\n\n let activeCount = 0;\n const queue: Array<() => void> = [];\n\n const dequeue = (): void => {\n if (queue.length > 0 && activeCount < limit) {\n const next = queue.shift();\n\n next?.();\n }\n };\n\n return async <T>(fn: () => Promise<T>): Promise<T> => {\n while (activeCount >= limit) {\n await new Promise<void>((resolve) => queue.push(resolve));\n }\n\n activeCount++;\n\n try {\n return await fn();\n } finally {\n activeCount--;\n dequeue();\n }\n };\n}\n"],"mappings":"0CAqBA,SAAgB,EAAK,EAAwD,CAC3E,EAAA,OAAO,GAAS,EAAG,gCAAiC,CAAE,KAAM,CAAE,QAAO,CAAE,KAAM,WAAY,CAAC,CAE1F,IAAI,EAAc,EACZ,EAA2B,EAAE,CAE7B,MAAsB,CACtB,EAAM,OAAS,GAAK,EAAc,GACvB,EAAM,OAAO,IAElB,EAIZ,OAAO,KAAU,IAAqC,CACpD,KAAO,GAAe,GACpB,MAAM,IAAI,QAAe,GAAY,EAAM,KAAK,EAAQ,CAAC,CAG3D,IAEA,GAAI,CACF,OAAO,MAAM,GAAI,QACT,CACR,IACA,GAAS"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a promise pool that limits the number of concurrent promises.
|
|
3
|
+
* Useful for rate limiting API calls or controlling resource usage.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* const requestPool = pool(3);
|
|
8
|
+
*
|
|
9
|
+
* const results = await Promise.all([
|
|
10
|
+
* requestPool(() => fetch('/api/1')),
|
|
11
|
+
* requestPool(() => fetch('/api/2')),
|
|
12
|
+
* requestPool(() => fetch('/api/3')),
|
|
13
|
+
* requestPool(() => fetch('/api/4')), // Will wait for one of the above to finish
|
|
14
|
+
* ]);
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @param limit - Maximum number of concurrent promises
|
|
18
|
+
* @returns Function that accepts a promise-returning function and executes it when a slot is available
|
|
19
|
+
*/
|
|
20
|
+
export declare function pool(limit: number): <T>(fn: () => Promise<T>) => Promise<T>;
|
|
21
|
+
//# sourceMappingURL=pool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../../src/async/pool.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CA4B3E"}
|
package/dist/async/pool.js
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
|
-
import { assert as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
import { assert as e } from "../function/assert.js";
|
|
2
|
+
//#region src/async/pool.ts
|
|
3
|
+
function t(t) {
|
|
4
|
+
e(t >= 1, "Pool limit must be at least 1", {
|
|
5
|
+
args: { limit: t },
|
|
6
|
+
type: RangeError
|
|
7
|
+
});
|
|
8
|
+
let n = 0, r = [], i = () => {
|
|
9
|
+
r.length > 0 && n < t && r.shift()?.();
|
|
10
|
+
};
|
|
11
|
+
return async (e) => {
|
|
12
|
+
for (; n >= t;) await new Promise((e) => r.push(e));
|
|
13
|
+
n++;
|
|
14
|
+
try {
|
|
15
|
+
return await e();
|
|
16
|
+
} finally {
|
|
17
|
+
n--, i();
|
|
18
|
+
}
|
|
19
|
+
};
|
|
18
20
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
//# sourceMappingURL=pool.js.map
|
|
21
|
+
//#endregion
|
|
22
|
+
export { t as pool };
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=pool.js.map
|
package/dist/async/pool.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pool.js","sources":["../../src/async/pool.ts"],"sourcesContent":["import { assert } from '../function/assert';\n\n/**\n * Creates a promise pool that limits the number of concurrent promises.\n * Useful for rate limiting API calls or controlling resource usage.\n *\n * @example\n * ```ts\n * const requestPool = pool(3);\n *\n * const results = await Promise.all([\n * requestPool(() => fetch('/api/1')),\n * requestPool(() => fetch('/api/2')),\n * requestPool(() => fetch('/api/3')),\n * requestPool(() => fetch('/api/4')), // Will wait for one of the above to finish\n * ]);\n * ```\n *\n * @param limit - Maximum number of concurrent promises\n * @returns Function that accepts a promise-returning function and executes it when a slot is available\n */\nexport function pool(limit: number): <T>(fn: () => Promise<T>) => Promise<T> {\n assert(limit >= 1, 'Pool limit must be at least 1', { args: { limit }, type: RangeError });\n\n let activeCount = 0;\n const queue: Array<() => void> = [];\n\n const dequeue = (): void => {\n if (queue.length > 0 && activeCount < limit) {\n const next = queue.shift();\n next?.();\n }\n };\n\n return async <T>(fn: () => Promise<T>): Promise<T> => {\n while (activeCount >= limit) {\n await new Promise<void>((resolve) => queue.push(resolve));\n }\n\n activeCount++;\n\n try {\n return await fn();\n } finally {\n activeCount--;\n dequeue();\n }\n };\n}\n"],"
|
|
1
|
+
{"version":3,"file":"pool.js","names":[],"sources":["../../src/async/pool.ts"],"sourcesContent":["import { assert } from '../function/assert';\n\n/**\n * Creates a promise pool that limits the number of concurrent promises.\n * Useful for rate limiting API calls or controlling resource usage.\n *\n * @example\n * ```ts\n * const requestPool = pool(3);\n *\n * const results = await Promise.all([\n * requestPool(() => fetch('/api/1')),\n * requestPool(() => fetch('/api/2')),\n * requestPool(() => fetch('/api/3')),\n * requestPool(() => fetch('/api/4')), // Will wait for one of the above to finish\n * ]);\n * ```\n *\n * @param limit - Maximum number of concurrent promises\n * @returns Function that accepts a promise-returning function and executes it when a slot is available\n */\nexport function pool(limit: number): <T>(fn: () => Promise<T>) => Promise<T> {\n assert(limit >= 1, 'Pool limit must be at least 1', { args: { limit }, type: RangeError });\n\n let activeCount = 0;\n const queue: Array<() => void> = [];\n\n const dequeue = (): void => {\n if (queue.length > 0 && activeCount < limit) {\n const next = queue.shift();\n\n next?.();\n }\n };\n\n return async <T>(fn: () => Promise<T>): Promise<T> => {\n while (activeCount >= limit) {\n await new Promise<void>((resolve) => queue.push(resolve));\n }\n\n activeCount++;\n\n try {\n return await fn();\n } finally {\n activeCount--;\n dequeue();\n }\n };\n}\n"],"mappings":";;AAqBA,SAAgB,EAAK,GAAwD;AAC3E,GAAO,KAAS,GAAG,iCAAiC;EAAE,MAAM,EAAE,UAAO;EAAE,MAAM;EAAY,CAAC;CAE1F,IAAI,IAAc,GACZ,IAA2B,EAAE,EAE7B,UAAsB;AAC1B,EAAI,EAAM,SAAS,KAAK,IAAc,KACvB,EAAM,OAAO,IAElB;;AAIZ,QAAO,OAAU,MAAqC;AACpD,SAAO,KAAe,GACpB,OAAM,IAAI,SAAe,MAAY,EAAM,KAAK,EAAQ,CAAC;AAG3D;AAEA,MAAI;AACF,UAAO,MAAM,GAAI;YACT;AAER,GADA,KACA,GAAS"}
|
package/dist/async/predict.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=predict.cjs.map
|
|
1
|
+
function e(e,t={}){let{signal:n,timeout:r=7e3}=t,i=n?AbortSignal.any([AbortSignal.timeout(r),n]):AbortSignal.timeout(r);return Promise.race([e(i),new Promise((e,t)=>{i.addEventListener(`abort`,()=>t(i.reason),{once:!0})})])}exports.predict=e;
|
|
2
|
+
//# sourceMappingURL=predict.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"predict.cjs","sources":["../../src/async/predict.ts"],"sourcesContent":["/**\n * Creates a Promise that can be aborted using an AbortController.\n *\n * @example\n * ```ts\n * const slowFn = () => new Promise(resolve => setTimeout(() => resolve('slow'), 10000));\n * const fastFn = () => new Promise(resolve => setTimeout(() => resolve('fast'), 5000));\n *\n * predict(slowFn); // rejects after 7 seconds\n * predict(fastFn); // resolves with 'fast' after 5 seconds\n * ```\n *\n * @param fn - The function to execute, which receives an AbortSignal.\n * @param options - The options for the abortable function.\n * @param [options.signal] - The AbortSignal to use for aborting the Promise.\n * @param [options.timeout=7000] - The timeout in milliseconds after which the Promise will be aborted.\n *\n * @returns - A Promise that resolves with the result of the callback or rejects if aborted.\n */\nexport function predict<T>(\n fn: (signal: AbortSignal) => Promise<T>,\n options: { signal?: AbortSignal; timeout?: number } = {},\n): Promise<T> {\n const { signal, timeout = 7000 } = options;\n const abortSignal = signal ? AbortSignal.any([AbortSignal.timeout(timeout), signal]) : AbortSignal.timeout(timeout);\n\n return Promise.race([\n fn(abortSignal),\n new Promise<never>((_, reject) => {\n abortSignal.addEventListener('abort', () => reject(
|
|
1
|
+
{"version":3,"file":"predict.cjs","names":[],"sources":["../../src/async/predict.ts"],"sourcesContent":["/**\n * Creates a Promise that can be aborted using an AbortController.\n *\n * @example\n * ```ts\n * const slowFn = () => new Promise(resolve => setTimeout(() => resolve('slow'), 10000));\n * const fastFn = () => new Promise(resolve => setTimeout(() => resolve('fast'), 5000));\n *\n * predict(slowFn); // rejects after 7 seconds\n * predict(fastFn); // resolves with 'fast' after 5 seconds\n * ```\n *\n * @param fn - The function to execute, which receives an AbortSignal.\n * @param options - The options for the abortable function.\n * @param [options.signal] - The AbortSignal to use for aborting the Promise.\n * @param [options.timeout=7000] - The timeout in milliseconds after which the Promise will be aborted.\n *\n * @returns - A Promise that resolves with the result of the callback or rejects if aborted.\n */\nexport function predict<T>(\n fn: (signal: AbortSignal) => Promise<T>,\n options: { signal?: AbortSignal; timeout?: number } = {},\n): Promise<T> {\n const { signal, timeout = 7000 } = options;\n const abortSignal = signal ? AbortSignal.any([AbortSignal.timeout(timeout), signal]) : AbortSignal.timeout(timeout);\n\n return Promise.race([\n fn(abortSignal),\n new Promise<never>((_, reject) => {\n abortSignal.addEventListener('abort', () => reject(abortSignal.reason), { once: true });\n }),\n ]);\n}\n"],"mappings":"AAmBA,SAAgB,EACd,EACA,EAAsD,EAAE,CAC5C,CACZ,GAAM,CAAE,SAAQ,UAAU,KAAS,EAC7B,EAAc,EAAS,YAAY,IAAI,CAAC,YAAY,QAAQ,EAAQ,CAAE,EAAO,CAAC,CAAG,YAAY,QAAQ,EAAQ,CAEnH,OAAO,QAAQ,KAAK,CAClB,EAAG,EAAY,CACf,IAAI,SAAgB,EAAG,IAAW,CAChC,EAAY,iBAAiB,YAAe,EAAO,EAAY,OAAO,CAAE,CAAE,KAAM,GAAM,CAAC,EACvF,CACH,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a Promise that can be aborted using an AbortController.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* const slowFn = () => new Promise(resolve => setTimeout(() => resolve('slow'), 10000));
|
|
7
|
+
* const fastFn = () => new Promise(resolve => setTimeout(() => resolve('fast'), 5000));
|
|
8
|
+
*
|
|
9
|
+
* predict(slowFn); // rejects after 7 seconds
|
|
10
|
+
* predict(fastFn); // resolves with 'fast' after 5 seconds
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @param fn - The function to execute, which receives an AbortSignal.
|
|
14
|
+
* @param options - The options for the abortable function.
|
|
15
|
+
* @param [options.signal] - The AbortSignal to use for aborting the Promise.
|
|
16
|
+
* @param [options.timeout=7000] - The timeout in milliseconds after which the Promise will be aborted.
|
|
17
|
+
*
|
|
18
|
+
* @returns - A Promise that resolves with the result of the callback or rejects if aborted.
|
|
19
|
+
*/
|
|
20
|
+
export declare function predict<T>(fn: (signal: AbortSignal) => Promise<T>, options?: {
|
|
21
|
+
signal?: AbortSignal;
|
|
22
|
+
timeout?: number;
|
|
23
|
+
}): Promise<T>;
|
|
24
|
+
//# sourceMappingURL=predict.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"predict.d.ts","sourceRoot":"","sources":["../../src/async/predict.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,OAAO,CAAC,CAAC,EACvB,EAAE,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,EACvC,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,WAAW,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAO,GACvD,OAAO,CAAC,CAAC,CAAC,CAUZ"}
|
package/dist/async/predict.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
})
|
|
8
|
-
]);
|
|
1
|
+
//#region src/async/predict.ts
|
|
2
|
+
function e(e, t = {}) {
|
|
3
|
+
let { signal: n, timeout: r = 7e3 } = t, i = n ? AbortSignal.any([AbortSignal.timeout(r), n]) : AbortSignal.timeout(r);
|
|
4
|
+
return Promise.race([e(i), new Promise((e, t) => {
|
|
5
|
+
i.addEventListener("abort", () => t(i.reason), { once: !0 });
|
|
6
|
+
})]);
|
|
9
7
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
//# sourceMappingURL=predict.js.map
|
|
8
|
+
//#endregion
|
|
9
|
+
export { e as predict };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=predict.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"predict.js","sources":["../../src/async/predict.ts"],"sourcesContent":["/**\n * Creates a Promise that can be aborted using an AbortController.\n *\n * @example\n * ```ts\n * const slowFn = () => new Promise(resolve => setTimeout(() => resolve('slow'), 10000));\n * const fastFn = () => new Promise(resolve => setTimeout(() => resolve('fast'), 5000));\n *\n * predict(slowFn); // rejects after 7 seconds\n * predict(fastFn); // resolves with 'fast' after 5 seconds\n * ```\n *\n * @param fn - The function to execute, which receives an AbortSignal.\n * @param options - The options for the abortable function.\n * @param [options.signal] - The AbortSignal to use for aborting the Promise.\n * @param [options.timeout=7000] - The timeout in milliseconds after which the Promise will be aborted.\n *\n * @returns - A Promise that resolves with the result of the callback or rejects if aborted.\n */\nexport function predict<T>(\n fn: (signal: AbortSignal) => Promise<T>,\n options: { signal?: AbortSignal; timeout?: number } = {},\n): Promise<T> {\n const { signal, timeout = 7000 } = options;\n const abortSignal = signal ? AbortSignal.any([AbortSignal.timeout(timeout), signal]) : AbortSignal.timeout(timeout);\n\n return Promise.race([\n fn(abortSignal),\n new Promise<never>((_, reject) => {\n abortSignal.addEventListener('abort', () => reject(
|
|
1
|
+
{"version":3,"file":"predict.js","names":[],"sources":["../../src/async/predict.ts"],"sourcesContent":["/**\n * Creates a Promise that can be aborted using an AbortController.\n *\n * @example\n * ```ts\n * const slowFn = () => new Promise(resolve => setTimeout(() => resolve('slow'), 10000));\n * const fastFn = () => new Promise(resolve => setTimeout(() => resolve('fast'), 5000));\n *\n * predict(slowFn); // rejects after 7 seconds\n * predict(fastFn); // resolves with 'fast' after 5 seconds\n * ```\n *\n * @param fn - The function to execute, which receives an AbortSignal.\n * @param options - The options for the abortable function.\n * @param [options.signal] - The AbortSignal to use for aborting the Promise.\n * @param [options.timeout=7000] - The timeout in milliseconds after which the Promise will be aborted.\n *\n * @returns - A Promise that resolves with the result of the callback or rejects if aborted.\n */\nexport function predict<T>(\n fn: (signal: AbortSignal) => Promise<T>,\n options: { signal?: AbortSignal; timeout?: number } = {},\n): Promise<T> {\n const { signal, timeout = 7000 } = options;\n const abortSignal = signal ? AbortSignal.any([AbortSignal.timeout(timeout), signal]) : AbortSignal.timeout(timeout);\n\n return Promise.race([\n fn(abortSignal),\n new Promise<never>((_, reject) => {\n abortSignal.addEventListener('abort', () => reject(abortSignal.reason), { once: true });\n }),\n ]);\n}\n"],"mappings":";AAmBA,SAAgB,EACd,GACA,IAAsD,EAAE,EAC5C;CACZ,IAAM,EAAE,WAAQ,aAAU,QAAS,GAC7B,IAAc,IAAS,YAAY,IAAI,CAAC,YAAY,QAAQ,EAAQ,EAAE,EAAO,CAAC,GAAG,YAAY,QAAQ,EAAQ;AAEnH,QAAO,QAAQ,KAAK,CAClB,EAAG,EAAY,EACf,IAAI,SAAgB,GAAG,MAAW;AAChC,IAAY,iBAAiB,eAAe,EAAO,EAAY,OAAO,EAAE,EAAE,MAAM,IAAM,CAAC;GACvF,CACH,CAAC"}
|
package/dist/async/queue.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=queue.cjs.map
|
|
1
|
+
const e=require(`../function/assert.cjs`),t=require(`./scheduler.cjs`);function n(n={}){let{concurrency:r=1}=n;e.assert(r>=1,`Concurrency must be at least 1`,{args:{concurrency:r},type:RangeError});let i=0,a=null,o=null,s=[],c=!1,l=()=>{c||(c=!0,new t.Scheduler().postTask(()=>{c=!1,u()},{priority:`user-visible`}))},u=()=>{if(i<r&&s.length>0){let e=s.shift();i++,e.fn().then(e.resolve).catch(e.reject).finally(()=>{i--,l(),i===0&&s.length===0&&o&&(o(),a=null,o=null)})}};return{add:e=>{let{promise:t,reject:n,resolve:r}=Promise.withResolvers();return s.push({fn:e,reject:n,resolve:r}),l(),t},clear:()=>{s.length=0},onIdle:()=>{if(i===0&&s.length===0)return Promise.resolve();if(!a){let e=Promise.withResolvers();a=e.promise,o=e.resolve}return a},get pending(){return i},get size(){return s.length}}}exports.queue=n;
|
|
2
|
+
//# sourceMappingURL=queue.cjs.map
|