@vielzeug/arsenal 1.0.1
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 +104 -0
- package/dist/_common/_abortable.d.ts +5 -0
- package/dist/_common/_abortable.d.ts.map +1 -0
- package/dist/_common/_lruMap.cjs +2 -0
- package/dist/_common/_lruMap.cjs.map +1 -0
- package/dist/_common/_lruMap.d.ts +20 -0
- package/dist/_common/_lruMap.d.ts.map +1 -0
- package/dist/_common/_lruMap.js +18 -0
- package/dist/_common/_lruMap.js.map +1 -0
- package/dist/_common/_secureRandomIndex.cjs +2 -0
- package/dist/_common/_secureRandomIndex.cjs.map +1 -0
- package/dist/_common/_secureRandomIndex.d.ts +2 -0
- package/dist/_common/_secureRandomIndex.d.ts.map +1 -0
- package/dist/_common/_secureRandomIndex.js +9 -0
- package/dist/_common/_secureRandomIndex.js.map +1 -0
- package/dist/_common/_selectorSet.cjs +2 -0
- package/dist/_common/_selectorSet.cjs.map +1 -0
- package/dist/_common/_selectorSet.d.ts +2 -0
- package/dist/_common/_selectorSet.d.ts.map +1 -0
- package/dist/_common/_selectorSet.js +16 -0
- package/dist/_common/_selectorSet.js.map +1 -0
- package/dist/_common/unsafePaths.cjs +2 -0
- package/dist/_common/unsafePaths.cjs.map +1 -0
- package/dist/_common/unsafePaths.d.ts +25 -0
- package/dist/_common/unsafePaths.d.ts.map +1 -0
- package/dist/_common/unsafePaths.js +13 -0
- package/dist/_common/unsafePaths.js.map +1 -0
- package/dist/_dev.cjs +2 -0
- package/dist/_dev.cjs.map +1 -0
- package/dist/_dev.d.ts +2 -0
- package/dist/_dev.d.ts.map +1 -0
- package/dist/_dev.js +9 -0
- package/dist/_dev.js.map +1 -0
- package/dist/array/chunk.cjs +2 -0
- package/dist/array/chunk.cjs.map +1 -0
- package/dist/array/chunk.d.ts +19 -0
- package/dist/array/chunk.d.ts.map +1 -0
- package/dist/array/chunk.js +12 -0
- package/dist/array/chunk.js.map +1 -0
- package/dist/array/compact.cjs +2 -0
- package/dist/array/compact.cjs.map +1 -0
- package/dist/array/compact.d.ts +7 -0
- package/dist/array/compact.d.ts.map +1 -0
- package/dist/array/compact.js +8 -0
- package/dist/array/compact.js.map +1 -0
- package/dist/array/compare.cjs +2 -0
- package/dist/array/compare.cjs.map +1 -0
- package/dist/array/compare.d.ts +31 -0
- package/dist/array/compare.d.ts.map +1 -0
- package/dist/array/compare.js +20 -0
- package/dist/array/compare.js.map +1 -0
- package/dist/array/compareBy.cjs +2 -0
- package/dist/array/compareBy.cjs.map +1 -0
- package/dist/array/compareBy.d.ts +24 -0
- package/dist/array/compareBy.d.ts.map +1 -0
- package/dist/array/compareBy.js +16 -0
- package/dist/array/compareBy.js.map +1 -0
- package/dist/array/contains.cjs +2 -0
- package/dist/array/contains.cjs.map +1 -0
- package/dist/array/contains.d.ts +17 -0
- package/dist/array/contains.d.ts.map +1 -0
- package/dist/array/contains.js +9 -0
- package/dist/array/contains.js.map +1 -0
- package/dist/array/countBy.cjs +2 -0
- package/dist/array/countBy.cjs.map +1 -0
- package/dist/array/countBy.d.ts +8 -0
- package/dist/array/countBy.d.ts.map +1 -0
- package/dist/array/countBy.js +14 -0
- package/dist/array/countBy.js.map +1 -0
- package/dist/array/difference.cjs +2 -0
- package/dist/array/difference.cjs.map +1 -0
- package/dist/array/difference.d.ts +6 -0
- package/dist/array/difference.d.ts.map +1 -0
- package/dist/array/difference.js +14 -0
- package/dist/array/difference.js.map +1 -0
- package/dist/array/drop.cjs +2 -0
- package/dist/array/drop.cjs.map +1 -0
- package/dist/array/drop.d.ts +5 -0
- package/dist/array/drop.d.ts.map +1 -0
- package/dist/array/drop.js +9 -0
- package/dist/array/drop.js.map +1 -0
- package/dist/array/dropLast.cjs +2 -0
- package/dist/array/dropLast.cjs.map +1 -0
- package/dist/array/dropLast.d.ts +5 -0
- package/dist/array/dropLast.d.ts.map +1 -0
- package/dist/array/dropLast.js +9 -0
- package/dist/array/dropLast.js.map +1 -0
- package/dist/array/filterMap.cjs +2 -0
- package/dist/array/filterMap.cjs.map +1 -0
- package/dist/array/filterMap.d.ts +5 -0
- package/dist/array/filterMap.d.ts.map +1 -0
- package/dist/array/filterMap.js +13 -0
- package/dist/array/filterMap.js.map +1 -0
- package/dist/array/first.cjs +2 -0
- package/dist/array/first.cjs.map +1 -0
- package/dist/array/first.d.ts +5 -0
- package/dist/array/first.d.ts.map +1 -0
- package/dist/array/first.js +8 -0
- package/dist/array/first.js.map +1 -0
- package/dist/array/flatten.cjs +2 -0
- package/dist/array/flatten.cjs.map +1 -0
- package/dist/array/flatten.d.ts +5 -0
- package/dist/array/flatten.d.ts.map +1 -0
- package/dist/array/flatten.js +11 -0
- package/dist/array/flatten.js.map +1 -0
- package/dist/array/groupBy.cjs +2 -0
- package/dist/array/groupBy.cjs.map +1 -0
- package/dist/array/groupBy.d.ts +7 -0
- package/dist/array/groupBy.d.ts.map +1 -0
- package/dist/array/groupBy.js +14 -0
- package/dist/array/groupBy.js.map +1 -0
- package/dist/array/index.d.ts +29 -0
- package/dist/array/index.d.ts.map +1 -0
- package/dist/array/indexBy.cjs +2 -0
- package/dist/array/indexBy.cjs.map +1 -0
- package/dist/array/indexBy.d.ts +7 -0
- package/dist/array/indexBy.d.ts.map +1 -0
- package/dist/array/indexBy.js +14 -0
- package/dist/array/indexBy.js.map +1 -0
- package/dist/array/intersection.cjs +2 -0
- package/dist/array/intersection.cjs.map +1 -0
- package/dist/array/intersection.d.ts +6 -0
- package/dist/array/intersection.d.ts.map +1 -0
- package/dist/array/intersection.js +14 -0
- package/dist/array/intersection.js.map +1 -0
- package/dist/array/last.cjs +2 -0
- package/dist/array/last.cjs.map +1 -0
- package/dist/array/last.d.ts +5 -0
- package/dist/array/last.d.ts.map +1 -0
- package/dist/array/last.js +8 -0
- package/dist/array/last.js.map +1 -0
- package/dist/array/partition.cjs +2 -0
- package/dist/array/partition.cjs.map +1 -0
- package/dist/array/partition.d.ts +5 -0
- package/dist/array/partition.d.ts.map +1 -0
- package/dist/array/partition.js +10 -0
- package/dist/array/partition.js.map +1 -0
- package/dist/array/replace.cjs +2 -0
- package/dist/array/replace.cjs.map +1 -0
- package/dist/array/replace.d.ts +18 -0
- package/dist/array/replace.d.ts.map +1 -0
- package/dist/array/replace.js +13 -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 +20 -0
- package/dist/array/rotate.d.ts.map +1 -0
- package/dist/array/rotate.js +10 -0
- package/dist/array/rotate.js.map +1 -0
- package/dist/array/search.cjs +2 -0
- package/dist/array/search.cjs.map +1 -0
- package/dist/array/search.d.ts +85 -0
- package/dist/array/search.d.ts.map +1 -0
- package/dist/array/search.js +47 -0
- package/dist/array/search.js.map +1 -0
- package/dist/array/sort.cjs +2 -0
- package/dist/array/sort.cjs.map +1 -0
- package/dist/array/sort.d.ts +26 -0
- package/dist/array/sort.d.ts.map +1 -0
- package/dist/array/sort.js +16 -0
- package/dist/array/sort.js.map +1 -0
- package/dist/array/take.cjs +2 -0
- package/dist/array/take.cjs.map +1 -0
- package/dist/array/take.d.ts +5 -0
- package/dist/array/take.d.ts.map +1 -0
- package/dist/array/take.js +9 -0
- package/dist/array/take.js.map +1 -0
- package/dist/array/takeLast.cjs +2 -0
- package/dist/array/takeLast.cjs.map +1 -0
- package/dist/array/takeLast.d.ts +5 -0
- package/dist/array/takeLast.d.ts.map +1 -0
- package/dist/array/takeLast.js +9 -0
- package/dist/array/takeLast.js.map +1 -0
- 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/union.cjs +2 -0
- package/dist/array/union.cjs.map +1 -0
- package/dist/array/union.d.ts +6 -0
- package/dist/array/union.d.ts.map +1 -0
- package/dist/array/union.js +9 -0
- package/dist/array/union.js.map +1 -0
- package/dist/array/uniq.cjs +2 -0
- package/dist/array/uniq.cjs.map +1 -0
- package/dist/array/uniq.d.ts +18 -0
- package/dist/array/uniq.d.ts.map +1 -0
- package/dist/array/uniq.js +9 -0
- package/dist/array/uniq.js.map +1 -0
- package/dist/array/unzip.cjs +2 -0
- package/dist/array/unzip.cjs.map +1 -0
- package/dist/array/unzip.d.ts +7 -0
- package/dist/array/unzip.d.ts.map +1 -0
- package/dist/array/unzip.js +11 -0
- package/dist/array/unzip.js.map +1 -0
- package/dist/array/zip.cjs +2 -0
- package/dist/array/zip.cjs.map +1 -0
- package/dist/array/zip.d.ts +7 -0
- package/dist/array/zip.d.ts.map +1 -0
- package/dist/array/zip.js +11 -0
- package/dist/array/zip.js.map +1 -0
- package/dist/arsenal.cjs +2 -0
- package/dist/arsenal.cjs.map +1 -0
- package/dist/arsenal.iife.js +2 -0
- package/dist/arsenal.iife.js.map +1 -0
- package/dist/arsenal.js +2 -0
- package/dist/arsenal.js.map +1 -0
- package/dist/async/abortError.cjs +2 -0
- package/dist/async/abortError.cjs.map +1 -0
- package/dist/async/abortError.d.ts +23 -0
- package/dist/async/abortError.d.ts.map +1 -0
- package/dist/async/abortError.js +8 -0
- package/dist/async/abortError.js.map +1 -0
- package/dist/async/attempt.cjs +2 -0
- package/dist/async/attempt.cjs.map +1 -0
- package/dist/async/attempt.d.ts +58 -0
- package/dist/async/attempt.d.ts.map +1 -0
- package/dist/async/attempt.js +31 -0
- package/dist/async/attempt.js.map +1 -0
- package/dist/async/backoff.cjs +2 -0
- package/dist/async/backoff.cjs.map +1 -0
- package/dist/async/backoff.d.ts +20 -0
- package/dist/async/backoff.d.ts.map +1 -0
- package/dist/async/backoff.js +9 -0
- package/dist/async/backoff.js.map +1 -0
- package/dist/async/index.d.ts +9 -0
- package/dist/async/index.d.ts.map +1 -0
- package/dist/async/parallel.cjs +2 -0
- package/dist/async/parallel.cjs.map +1 -0
- package/dist/async/parallel.d.ts +42 -0
- package/dist/async/parallel.d.ts.map +1 -0
- package/dist/async/parallel.js +26 -0
- package/dist/async/parallel.js.map +1 -0
- package/dist/async/queue.cjs +2 -0
- package/dist/async/queue.cjs.map +1 -0
- package/dist/async/queue.d.ts +42 -0
- package/dist/async/queue.d.ts.map +1 -0
- package/dist/async/queue.js +72 -0
- package/dist/async/queue.js.map +1 -0
- package/dist/async/retry.cjs +2 -0
- package/dist/async/retry.cjs.map +1 -0
- package/dist/async/retry.d.ts +46 -0
- package/dist/async/retry.d.ts.map +1 -0
- package/dist/async/retry.js +26 -0
- package/dist/async/retry.js.map +1 -0
- package/dist/async/sleep.cjs +2 -0
- package/dist/async/sleep.cjs.map +1 -0
- package/dist/async/sleep.d.ts +21 -0
- package/dist/async/sleep.d.ts.map +1 -0
- package/dist/async/sleep.js +16 -0
- package/dist/async/sleep.js.map +1 -0
- package/dist/async/waitFor.cjs +2 -0
- package/dist/async/waitFor.cjs.map +1 -0
- package/dist/async/waitFor.d.ts +34 -0
- package/dist/async/waitFor.d.ts.map +1 -0
- package/dist/async/waitFor.js +13 -0
- package/dist/async/waitFor.js.map +1 -0
- package/dist/cache/index.d.ts +3 -0
- package/dist/cache/index.d.ts.map +1 -0
- package/dist/cache/memo.cjs +2 -0
- package/dist/cache/memo.cjs.map +1 -0
- package/dist/cache/memo.d.ts +40 -0
- package/dist/cache/memo.d.ts.map +1 -0
- package/dist/cache/memo.js +37 -0
- package/dist/cache/memo.js.map +1 -0
- package/dist/cache/stash.cjs +2 -0
- package/dist/cache/stash.cjs.map +1 -0
- package/dist/cache/stash.d.ts +111 -0
- package/dist/cache/stash.d.ts.map +1 -0
- package/dist/cache/stash.js +92 -0
- package/dist/cache/stash.js.map +1 -0
- package/dist/errors.cjs +2 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.ts +20 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +13 -0
- package/dist/errors.js.map +1 -0
- package/dist/function/assert.cjs +2 -0
- package/dist/function/assert.cjs.map +1 -0
- package/dist/function/assert.d.ts +19 -0
- package/dist/function/assert.d.ts.map +1 -0
- package/dist/function/assert.js +8 -0
- package/dist/function/assert.js.map +1 -0
- package/dist/function/constant.cjs +2 -0
- package/dist/function/constant.cjs.map +1 -0
- package/dist/function/constant.d.ts +5 -0
- package/dist/function/constant.d.ts.map +1 -0
- package/dist/function/constant.js +8 -0
- package/dist/function/constant.js.map +1 -0
- package/dist/function/debounce.cjs +2 -0
- package/dist/function/debounce.cjs.map +1 -0
- package/dist/function/debounce.d.ts +31 -0
- package/dist/function/debounce.d.ts.map +1 -0
- package/dist/function/debounce.js +29 -0
- package/dist/function/debounce.js.map +1 -0
- package/dist/function/identity.cjs +2 -0
- package/dist/function/identity.cjs.map +1 -0
- package/dist/function/identity.d.ts +5 -0
- package/dist/function/identity.d.ts.map +1 -0
- package/dist/function/identity.js +8 -0
- package/dist/function/identity.js.map +1 -0
- package/dist/function/index.d.ts +10 -0
- package/dist/function/index.d.ts.map +1 -0
- package/dist/function/once.cjs +2 -0
- package/dist/function/once.cjs.map +1 -0
- package/dist/function/once.d.ts +32 -0
- package/dist/function/once.d.ts.map +1 -0
- package/dist/function/once.js +11 -0
- package/dist/function/once.js.map +1 -0
- package/dist/function/pipe.cjs +2 -0
- package/dist/function/pipe.cjs.map +1 -0
- package/dist/function/pipe.d.ts +32 -0
- package/dist/function/pipe.d.ts.map +1 -0
- package/dist/function/pipe.js +10 -0
- package/dist/function/pipe.js.map +1 -0
- package/dist/function/runAll.cjs +2 -0
- package/dist/function/runAll.cjs.map +1 -0
- package/dist/function/runAll.d.ts +15 -0
- package/dist/function/runAll.d.ts.map +1 -0
- package/dist/function/runAll.js +19 -0
- package/dist/function/runAll.js.map +1 -0
- package/dist/function/tap.cjs +2 -0
- package/dist/function/tap.cjs.map +1 -0
- package/dist/function/tap.d.ts +5 -0
- package/dist/function/tap.d.ts.map +1 -0
- package/dist/function/tap.js +8 -0
- package/dist/function/tap.js.map +1 -0
- package/dist/function/throttle.cjs +2 -0
- package/dist/function/throttle.cjs.map +1 -0
- package/dist/function/throttle.d.ts +23 -0
- package/dist/function/throttle.d.ts.map +1 -0
- package/dist/function/throttle.js +36 -0
- package/dist/function/throttle.js.map +1 -0
- package/dist/guards/combinators.cjs +2 -0
- package/dist/guards/combinators.cjs.map +1 -0
- package/dist/guards/combinators.d.ts +49 -0
- package/dist/guards/combinators.d.ts.map +1 -0
- package/dist/guards/combinators.js +17 -0
- package/dist/guards/combinators.js.map +1 -0
- package/dist/guards/index.d.ts +20 -0
- package/dist/guards/index.d.ts.map +1 -0
- package/dist/guards/isAbortError.cjs +2 -0
- package/dist/guards/isAbortError.cjs.map +1 -0
- package/dist/guards/isAbortError.d.ts +19 -0
- package/dist/guards/isAbortError.d.ts.map +1 -0
- package/dist/guards/isAbortError.js +8 -0
- package/dist/guards/isAbortError.js.map +1 -0
- package/dist/guards/isArray.cjs +2 -0
- package/dist/guards/isArray.cjs.map +1 -0
- package/dist/guards/isArray.d.ts +16 -0
- package/dist/guards/isArray.d.ts.map +1 -0
- package/dist/guards/isArray.js +8 -0
- package/dist/guards/isArray.js.map +1 -0
- package/dist/guards/isBoolean.cjs +2 -0
- package/dist/guards/isBoolean.cjs.map +1 -0
- package/dist/guards/isBoolean.d.ts +23 -0
- package/dist/guards/isBoolean.d.ts.map +1 -0
- package/dist/guards/isBoolean.js +8 -0
- package/dist/guards/isBoolean.js.map +1 -0
- package/dist/guards/isDate.cjs +2 -0
- package/dist/guards/isDate.cjs.map +1 -0
- package/dist/guards/isDate.d.ts +15 -0
- package/dist/guards/isDate.d.ts.map +1 -0
- package/dist/guards/isDate.js +8 -0
- package/dist/guards/isDate.js.map +1 -0
- package/dist/guards/isDefined.cjs +2 -0
- package/dist/guards/isDefined.cjs.map +1 -0
- package/dist/guards/isDefined.d.ts +19 -0
- package/dist/guards/isDefined.d.ts.map +1 -0
- package/dist/guards/isDefined.js +8 -0
- package/dist/guards/isDefined.js.map +1 -0
- package/dist/guards/isEmpty.cjs +2 -0
- package/dist/guards/isEmpty.cjs.map +1 -0
- package/dist/guards/isEmpty.d.ts +23 -0
- package/dist/guards/isEmpty.d.ts.map +1 -0
- package/dist/guards/isEmpty.js +10 -0
- package/dist/guards/isEmpty.js.map +1 -0
- package/dist/guards/isEqual.cjs +2 -0
- package/dist/guards/isEqual.cjs.map +1 -0
- package/dist/guards/isEqual.d.ts +24 -0
- package/dist/guards/isEqual.d.ts.map +1 -0
- package/dist/guards/isEqual.js +34 -0
- package/dist/guards/isEqual.js.map +1 -0
- package/dist/guards/isError.cjs +2 -0
- package/dist/guards/isError.cjs.map +1 -0
- package/dist/guards/isError.d.ts +15 -0
- package/dist/guards/isError.d.ts.map +1 -0
- package/dist/guards/isError.js +8 -0
- package/dist/guards/isError.js.map +1 -0
- package/dist/guards/isFunction.cjs +2 -0
- package/dist/guards/isFunction.cjs.map +1 -0
- package/dist/guards/isFunction.d.ts +16 -0
- package/dist/guards/isFunction.d.ts.map +1 -0
- package/dist/guards/isFunction.js +8 -0
- package/dist/guards/isFunction.js.map +1 -0
- package/dist/guards/isMatch.cjs +2 -0
- package/dist/guards/isMatch.cjs.map +1 -0
- package/dist/guards/isMatch.d.ts +23 -0
- package/dist/guards/isMatch.d.ts.map +1 -0
- package/dist/guards/isMatch.js +23 -0
- package/dist/guards/isMatch.js.map +1 -0
- package/dist/guards/isNil.cjs +2 -0
- package/dist/guards/isNil.cjs.map +1 -0
- package/dist/guards/isNil.d.ts +17 -0
- package/dist/guards/isNil.d.ts.map +1 -0
- package/dist/guards/isNil.js +8 -0
- package/dist/guards/isNil.js.map +1 -0
- package/dist/guards/isNumber.cjs +2 -0
- package/dist/guards/isNumber.cjs.map +1 -0
- package/dist/guards/isNumber.d.ts +15 -0
- package/dist/guards/isNumber.d.ts.map +1 -0
- package/dist/guards/isNumber.js +8 -0
- package/dist/guards/isNumber.js.map +1 -0
- package/dist/guards/isPlainObject.cjs +2 -0
- package/dist/guards/isPlainObject.cjs.map +1 -0
- package/dist/guards/isPlainObject.d.ts +16 -0
- package/dist/guards/isPlainObject.d.ts.map +1 -0
- package/dist/guards/isPlainObject.js +10 -0
- package/dist/guards/isPlainObject.js.map +1 -0
- package/dist/guards/isPrimitive.cjs +2 -0
- package/dist/guards/isPrimitive.cjs.map +1 -0
- package/dist/guards/isPrimitive.d.ts +18 -0
- package/dist/guards/isPrimitive.d.ts.map +1 -0
- package/dist/guards/isPrimitive.js +9 -0
- package/dist/guards/isPrimitive.js.map +1 -0
- package/dist/guards/isPromise.cjs +2 -0
- package/dist/guards/isPromise.cjs.map +1 -0
- package/dist/guards/isPromise.d.ts +17 -0
- package/dist/guards/isPromise.d.ts.map +1 -0
- package/dist/guards/isPromise.js +8 -0
- package/dist/guards/isPromise.js.map +1 -0
- package/dist/guards/isRegex.cjs +2 -0
- package/dist/guards/isRegex.cjs.map +1 -0
- package/dist/guards/isRegex.d.ts +21 -0
- package/dist/guards/isRegex.d.ts.map +1 -0
- package/dist/guards/isRegex.js +8 -0
- package/dist/guards/isRegex.js.map +1 -0
- package/dist/guards/isString.cjs +2 -0
- package/dist/guards/isString.cjs.map +1 -0
- package/dist/guards/isString.d.ts +15 -0
- package/dist/guards/isString.d.ts.map +1 -0
- package/dist/guards/isString.js +8 -0
- package/dist/guards/isString.js.map +1 -0
- package/dist/guards/shallowEqual.cjs +2 -0
- package/dist/guards/shallowEqual.cjs.map +1 -0
- package/dist/guards/shallowEqual.d.ts +29 -0
- package/dist/guards/shallowEqual.d.ts.map +1 -0
- package/dist/guards/shallowEqual.js +20 -0
- package/dist/guards/shallowEqual.js.map +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +119 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +118 -0
- package/dist/math/abs.cjs +2 -0
- package/dist/math/abs.cjs.map +1 -0
- package/dist/math/abs.d.ts +17 -0
- package/dist/math/abs.d.ts.map +1 -0
- package/dist/math/abs.js +8 -0
- package/dist/math/abs.js.map +1 -0
- package/dist/math/allocate.cjs +2 -0
- package/dist/math/allocate.cjs.map +1 -0
- package/dist/math/allocate.d.ts +29 -0
- package/dist/math/allocate.d.ts.map +1 -0
- package/dist/math/allocate.js +20 -0
- package/dist/math/allocate.js.map +1 -0
- package/dist/math/average.cjs +2 -0
- package/dist/math/average.cjs.map +1 -0
- package/dist/math/average.d.ts +16 -0
- package/dist/math/average.d.ts.map +1 -0
- package/dist/math/average.js +14 -0
- package/dist/math/average.js.map +1 -0
- package/dist/math/clamp.cjs +2 -0
- package/dist/math/clamp.cjs.map +1 -0
- package/dist/math/clamp.d.ts +21 -0
- package/dist/math/clamp.d.ts.map +1 -0
- package/dist/math/clamp.js +8 -0
- package/dist/math/clamp.js.map +1 -0
- package/dist/math/gcd.cjs +2 -0
- package/dist/math/gcd.cjs.map +1 -0
- package/dist/math/gcd.d.ts +18 -0
- package/dist/math/gcd.d.ts.map +1 -0
- package/dist/math/gcd.js +13 -0
- package/dist/math/gcd.js.map +1 -0
- package/dist/math/index.d.ts +20 -0
- package/dist/math/index.d.ts.map +1 -0
- package/dist/math/lcm.cjs +2 -0
- package/dist/math/lcm.cjs.map +1 -0
- package/dist/math/lcm.d.ts +15 -0
- package/dist/math/lcm.d.ts.map +1 -0
- package/dist/math/lcm.js +9 -0
- package/dist/math/lcm.js.map +1 -0
- package/dist/math/lerp.cjs +2 -0
- package/dist/math/lerp.cjs.map +1 -0
- package/dist/math/lerp.d.ts +17 -0
- package/dist/math/lerp.d.ts.map +1 -0
- package/dist/math/lerp.js +8 -0
- package/dist/math/lerp.js.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 -0
- package/dist/math/max.cjs.map +1 -0
- package/dist/math/max.d.ts +21 -0
- package/dist/math/max.d.ts.map +1 -0
- package/dist/math/max.js +12 -0
- package/dist/math/max.js.map +1 -0
- package/dist/math/median.cjs +2 -0
- package/dist/math/median.cjs.map +1 -0
- package/dist/math/median.d.ts +17 -0
- package/dist/math/median.d.ts.map +1 -0
- package/dist/math/median.js +12 -0
- package/dist/math/median.js.map +1 -0
- package/dist/math/min.cjs +2 -0
- package/dist/math/min.cjs.map +1 -0
- package/dist/math/min.d.ts +21 -0
- package/dist/math/min.d.ts.map +1 -0
- package/dist/math/min.js +12 -0
- package/dist/math/min.js.map +1 -0
- package/dist/math/mod.cjs +2 -0
- package/dist/math/mod.cjs.map +1 -0
- package/dist/math/mod.d.ts +18 -0
- package/dist/math/mod.d.ts.map +1 -0
- package/dist/math/mod.js +10 -0
- package/dist/math/mod.js.map +1 -0
- package/dist/math/normalize.cjs +2 -0
- package/dist/math/normalize.cjs.map +1 -0
- package/dist/math/normalize.d.ts +18 -0
- package/dist/math/normalize.d.ts.map +1 -0
- package/dist/math/normalize.js +9 -0
- package/dist/math/normalize.js.map +1 -0
- 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 -0
- package/dist/math/range.cjs.map +1 -0
- package/dist/math/range.d.ts +37 -0
- package/dist/math/range.d.ts.map +1 -0
- package/dist/math/range.js +27 -0
- package/dist/math/range.js.map +1 -0
- package/dist/math/round.cjs +2 -0
- package/dist/math/round.cjs.map +1 -0
- package/dist/math/round.d.ts +21 -0
- package/dist/math/round.d.ts.map +1 -0
- package/dist/math/round.js +10 -0
- package/dist/math/round.js.map +1 -0
- package/dist/math/standardDeviation.cjs +2 -0
- package/dist/math/standardDeviation.cjs.map +1 -0
- package/dist/math/standardDeviation.d.ts +16 -0
- package/dist/math/standardDeviation.d.ts.map +1 -0
- package/dist/math/standardDeviation.js +9 -0
- package/dist/math/standardDeviation.js.map +1 -0
- package/dist/math/sum.cjs +2 -0
- package/dist/math/sum.cjs.map +1 -0
- package/dist/math/sum.d.ts +19 -0
- package/dist/math/sum.d.ts.map +1 -0
- package/dist/math/sum.js +13 -0
- package/dist/math/sum.js.map +1 -0
- package/dist/math/variance.cjs +2 -0
- package/dist/math/variance.cjs.map +1 -0
- package/dist/math/variance.d.ts +17 -0
- package/dist/math/variance.d.ts.map +1 -0
- package/dist/math/variance.js +11 -0
- package/dist/math/variance.js.map +1 -0
- package/dist/object/defaults.cjs +2 -0
- package/dist/object/defaults.cjs.map +1 -0
- package/dist/object/defaults.d.ts +17 -0
- package/dist/object/defaults.d.ts.map +1 -0
- package/dist/object/defaults.js +12 -0
- package/dist/object/defaults.js.map +1 -0
- package/dist/object/diff.cjs +2 -0
- package/dist/object/diff.cjs.map +1 -0
- package/dist/object/diff.d.ts +63 -0
- package/dist/object/diff.d.ts.map +1 -0
- package/dist/object/diff.js +27 -0
- package/dist/object/diff.js.map +1 -0
- package/dist/object/filterValues.cjs +2 -0
- package/dist/object/filterValues.cjs.map +1 -0
- package/dist/object/filterValues.d.ts +16 -0
- package/dist/object/filterValues.d.ts.map +1 -0
- package/dist/object/filterValues.js +11 -0
- package/dist/object/filterValues.js.map +1 -0
- package/dist/object/flattenPaths.cjs +2 -0
- package/dist/object/flattenPaths.cjs.map +1 -0
- package/dist/object/flattenPaths.d.ts +13 -0
- package/dist/object/flattenPaths.d.ts.map +1 -0
- package/dist/object/flattenPaths.js +31 -0
- package/dist/object/flattenPaths.js.map +1 -0
- package/dist/object/getPath.cjs +2 -0
- package/dist/object/getPath.cjs.map +1 -0
- package/dist/object/getPath.d.ts +48 -0
- package/dist/object/getPath.d.ts.map +1 -0
- package/dist/object/getPath.js +27 -0
- package/dist/object/getPath.js.map +1 -0
- package/dist/object/hash.cjs +2 -0
- package/dist/object/hash.cjs.map +1 -0
- package/dist/object/hash.d.ts +12 -0
- package/dist/object/hash.d.ts.map +1 -0
- package/dist/object/hash.js +28 -0
- package/dist/object/hash.js.map +1 -0
- package/dist/object/index.d.ts +15 -0
- package/dist/object/index.d.ts.map +1 -0
- package/dist/object/invert.cjs +2 -0
- package/dist/object/invert.cjs.map +1 -0
- package/dist/object/invert.d.ts +15 -0
- package/dist/object/invert.d.ts.map +1 -0
- package/dist/object/invert.js +11 -0
- package/dist/object/invert.js.map +1 -0
- package/dist/object/mapKeys.cjs +2 -0
- package/dist/object/mapKeys.cjs.map +1 -0
- package/dist/object/mapKeys.d.ts +16 -0
- package/dist/object/mapKeys.d.ts.map +1 -0
- package/dist/object/mapKeys.js +15 -0
- package/dist/object/mapKeys.js.map +1 -0
- package/dist/object/mapValues.cjs +2 -0
- package/dist/object/mapValues.cjs.map +1 -0
- package/dist/object/mapValues.d.ts +18 -0
- package/dist/object/mapValues.d.ts.map +1 -0
- package/dist/object/mapValues.js +11 -0
- package/dist/object/mapValues.js.map +1 -0
- package/dist/object/merge.cjs +2 -0
- package/dist/object/merge.cjs.map +1 -0
- package/dist/object/merge.d.ts +41 -0
- package/dist/object/merge.d.ts.map +1 -0
- package/dist/object/merge.js +27 -0
- package/dist/object/merge.js.map +1 -0
- package/dist/object/omit.cjs +2 -0
- package/dist/object/omit.cjs.map +1 -0
- package/dist/object/omit.d.ts +16 -0
- package/dist/object/omit.d.ts.map +1 -0
- package/dist/object/omit.js +11 -0
- package/dist/object/omit.js.map +1 -0
- package/dist/object/parseJSON.cjs +2 -0
- package/dist/object/parseJSON.cjs.map +1 -0
- package/dist/object/parseJSON.d.ts +32 -0
- package/dist/object/parseJSON.d.ts.map +1 -0
- package/dist/object/parseJSON.js +16 -0
- package/dist/object/parseJSON.js.map +1 -0
- package/dist/object/pick.cjs +2 -0
- package/dist/object/pick.cjs.map +1 -0
- package/dist/object/pick.d.ts +17 -0
- package/dist/object/pick.d.ts.map +1 -0
- package/dist/object/pick.js +11 -0
- package/dist/object/pick.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 +26 -0
- package/dist/object/prune.d.ts.map +1 -0
- package/dist/object/prune.js +36 -0
- package/dist/object/prune.js.map +1 -0
- package/dist/random/draw.cjs +2 -0
- package/dist/random/draw.cjs.map +1 -0
- package/dist/random/draw.d.ts +24 -0
- package/dist/random/draw.d.ts.map +1 -0
- package/dist/random/draw.js +21 -0
- package/dist/random/draw.js.map +1 -0
- package/dist/random/index.d.ts +5 -0
- package/dist/random/index.d.ts.map +1 -0
- package/dist/random/random.cjs +2 -0
- package/dist/random/random.cjs.map +1 -0
- package/dist/random/random.d.ts +14 -0
- package/dist/random/random.d.ts.map +1 -0
- package/dist/random/random.js +11 -0
- package/dist/random/random.js.map +1 -0
- package/dist/random/shuffle.cjs +2 -0
- package/dist/random/shuffle.cjs.map +1 -0
- package/dist/random/shuffle.d.ts +12 -0
- package/dist/random/shuffle.d.ts.map +1 -0
- package/dist/random/shuffle.js +14 -0
- package/dist/random/shuffle.js.map +1 -0
- package/dist/random/uuid.cjs +2 -0
- package/dist/random/uuid.cjs.map +1 -0
- package/dist/random/uuid.d.ts +12 -0
- package/dist/random/uuid.d.ts.map +1 -0
- package/dist/random/uuid.js +8 -0
- package/dist/random/uuid.js.map +1 -0
- package/dist/string/_caseUtils.cjs +2 -0
- package/dist/string/_caseUtils.cjs.map +1 -0
- package/dist/string/_caseUtils.d.ts +9 -0
- package/dist/string/_caseUtils.d.ts.map +1 -0
- package/dist/string/_caseUtils.js +13 -0
- package/dist/string/_caseUtils.js.map +1 -0
- package/dist/string/camelCase.cjs +2 -0
- package/dist/string/camelCase.cjs.map +1 -0
- package/dist/string/camelCase.d.ts +14 -0
- package/dist/string/camelCase.d.ts.map +1 -0
- package/dist/string/camelCase.js +9 -0
- package/dist/string/camelCase.js.map +1 -0
- package/dist/string/endsWith.cjs +2 -0
- package/dist/string/endsWith.cjs.map +1 -0
- package/dist/string/endsWith.d.ts +5 -0
- package/dist/string/endsWith.d.ts.map +1 -0
- package/dist/string/endsWith.js +8 -0
- package/dist/string/endsWith.js.map +1 -0
- package/dist/string/escape.cjs +2 -0
- package/dist/string/escape.cjs.map +1 -0
- package/dist/string/escape.d.ts +5 -0
- package/dist/string/escape.d.ts.map +1 -0
- package/dist/string/escape.js +15 -0
- package/dist/string/escape.js.map +1 -0
- package/dist/string/index.d.ts +14 -0
- package/dist/string/index.d.ts.map +1 -0
- package/dist/string/kebabCase.cjs +2 -0
- package/dist/string/kebabCase.cjs.map +1 -0
- package/dist/string/kebabCase.d.ts +15 -0
- package/dist/string/kebabCase.d.ts.map +1 -0
- package/dist/string/kebabCase.js +9 -0
- package/dist/string/kebabCase.js.map +1 -0
- package/dist/string/pad.cjs +2 -0
- package/dist/string/pad.cjs.map +1 -0
- package/dist/string/pad.d.ts +5 -0
- package/dist/string/pad.d.ts.map +1 -0
- package/dist/string/pad.js +10 -0
- package/dist/string/pad.js.map +1 -0
- package/dist/string/pascalCase.cjs +2 -0
- package/dist/string/pascalCase.cjs.map +1 -0
- package/dist/string/pascalCase.d.ts +15 -0
- package/dist/string/pascalCase.d.ts.map +1 -0
- package/dist/string/pascalCase.js +9 -0
- package/dist/string/pascalCase.js.map +1 -0
- package/dist/string/similarity.cjs +2 -0
- package/dist/string/similarity.cjs.map +1 -0
- package/dist/string/similarity.d.ts +2 -0
- package/dist/string/similarity.d.ts.map +1 -0
- package/dist/string/similarity.js +24 -0
- package/dist/string/similarity.js.map +1 -0
- package/dist/string/snakeCase.cjs +2 -0
- package/dist/string/snakeCase.cjs.map +1 -0
- package/dist/string/snakeCase.d.ts +15 -0
- package/dist/string/snakeCase.d.ts.map +1 -0
- package/dist/string/snakeCase.js +9 -0
- package/dist/string/snakeCase.js.map +1 -0
- package/dist/string/startsWith.cjs +2 -0
- package/dist/string/startsWith.cjs.map +1 -0
- package/dist/string/startsWith.d.ts +5 -0
- package/dist/string/startsWith.d.ts.map +1 -0
- package/dist/string/startsWith.js +8 -0
- package/dist/string/startsWith.js.map +1 -0
- package/dist/string/titleCase.cjs +2 -0
- package/dist/string/titleCase.cjs.map +1 -0
- package/dist/string/titleCase.d.ts +5 -0
- package/dist/string/titleCase.d.ts.map +1 -0
- package/dist/string/titleCase.js +9 -0
- package/dist/string/titleCase.js.map +1 -0
- package/dist/string/truncate.cjs +2 -0
- package/dist/string/truncate.cjs.map +1 -0
- package/dist/string/truncate.d.ts +27 -0
- package/dist/string/truncate.d.ts.map +1 -0
- package/dist/string/truncate.js +17 -0
- package/dist/string/truncate.js.map +1 -0
- package/dist/string/unescape.cjs +2 -0
- package/dist/string/unescape.cjs.map +1 -0
- package/dist/string/unescape.d.ts +5 -0
- package/dist/string/unescape.d.ts.map +1 -0
- package/dist/string/unescape.js +15 -0
- package/dist/string/unescape.js.map +1 -0
- package/dist/string/words.cjs +2 -0
- package/dist/string/words.cjs.map +1 -0
- package/dist/string/words.d.ts +5 -0
- package/dist/string/words.d.ts.map +1 -0
- package/dist/string/words.js +10 -0
- package/dist/string/words.js.map +1 -0
- package/dist/types.d.ts +13 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +102 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abortError.js","names":[],"sources":["../../src/async/abortError.ts"],"sourcesContent":["/**\n * Returns the abort error for the given signal.\n *\n * If the signal has a `reason`, that is returned directly (preserving the\n * original error thrown by `AbortController.abort(reason)`).\n * Otherwise, returns a `DOMException` with `name === 'AbortError'`.\n *\n * @example\n * ```ts\n * const ac = new AbortController();\n * ac.abort();\n * throw abortError(ac.signal); // DOMException { name: 'AbortError' }\n *\n * const ac2 = new AbortController();\n * ac2.abort(new TypeError('custom'));\n * throw abortError(ac2.signal); // TypeError('custom')\n * ```\n *\n * @param signal - The aborted signal to extract the error from.\n * @returns The abort reason, or a new `DOMException('Aborted', 'AbortError')`.\n */\nexport function abortError(signal?: AbortSignal): unknown {\n return signal?.reason ?? new DOMException('Aborted', 'AbortError');\n}\n"],"mappings":";AAqBA,SAAgB,EAAW,GAA+B;CACxD,OAAO,GAAQ,UAAU,IAAI,aAAa,WAAW,YAAY;AACnE"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function e(e){return e.ok===!0}function t(e){return e.ok===!1}function n(e){try{let t=e();return typeof t?.then==`function`?t.then(e=>({ok:!0,value:e}),e=>({error:e,ok:!1})):{ok:!0,value:t}}catch(e){return{error:e,ok:!1}}}exports.attempt=n,exports.isFail=t,exports.isOk=e;
|
|
2
|
+
//# sourceMappingURL=attempt.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attempt.cjs","names":[],"sources":["../../src/async/attempt.ts"],"sourcesContent":["export type AttemptResult<T> =\n | { ok: true; value: T }\n // eslint-disable-next-line perfectionist/sort-object-types\n | { ok: false; error: unknown };\n\n/**\n * Narrows an `AttemptResult` to the success branch.\n * @example\n * ```ts\n * const result = await attempt(() => fetch('/api').then(r => r.json()));\n * if (isOk(result)) console.log(result.value);\n * ```\n */\n\nexport function isOk<T>(result: AttemptResult<T>): result is { ok: true; value: T } {\n return result.ok === true;\n}\n\n/**\n * Narrows an `AttemptResult` to the failure branch.\n * @example\n * ```ts\n * const result = await attempt(() => fetch('/api').then(r => r.json()));\n * if (isFail(result)) console.error(result.error);\n * ```\n */\n// eslint-disable-next-line perfectionist/sort-object-types\nexport function isFail<T>(result: AttemptResult<T>): result is { ok: false; error: unknown } {\n return result.ok === false;\n}\n\n/**\n * Executes a function — sync or async — and returns an `AttemptResult` (or\n * `Promise<AttemptResult>` for async factories). Never throws.\n *\n * TypeScript infers the return type from the factory:\n * - sync factory → `AttemptResult<T>`\n * - async factory → `Promise<AttemptResult<T>>`\n *\n * @example\n * ```ts\n * // Sync\n * const parsed = attempt(() => JSON.parse(rawJson));\n * if (parsed.ok) console.log(parsed.value);\n * else console.error(parsed.error);\n *\n * // Async\n * const result = await attempt(() => fetch('/api').then(r => r.json()));\n * if (result.ok) console.log(result.value);\n * else console.error(result.error);\n *\n * // Combined with retry()\n * const result = await attempt(() => retry(fn, { times: 3 }));\n * ```\n */\nexport function attempt<T>(fn: () => Promise<T>): Promise<AttemptResult<T>>;\nexport function attempt<T>(fn: () => T): AttemptResult<T>;\nexport function attempt<T>(fn: () => T | Promise<T>): AttemptResult<T> | Promise<AttemptResult<T>> {\n try {\n const result = fn();\n\n if (typeof (result as PromiseLike<T>)?.then === 'function') {\n return (result as Promise<T>).then(\n (value) => ({ ok: true as const, value }),\n (error) => ({ error, ok: false as const }),\n );\n }\n\n return { ok: true, value: result as T };\n } catch (error) {\n return { error, ok: false };\n }\n}\n"],"mappings":"AAcA,SAAgB,EAAQ,EAA4D,CAClF,OAAO,EAAO,KAAO,EACvB,CAWA,SAAgB,EAAU,EAAmE,CAC3F,OAAO,EAAO,KAAO,EACvB,CA4BA,SAAgB,EAAW,EAAwE,CACjG,GAAI,CACF,IAAM,EAAS,EAAG,EASlB,OAPI,OAAQ,GAA2B,MAAS,WACtC,EAAsB,KAC3B,IAAW,CAAE,GAAI,GAAe,OAAM,GACtC,IAAW,CAAE,QAAO,GAAI,EAAe,EAC1C,EAGK,CAAE,GAAI,GAAM,MAAO,CAAY,CACxC,OAAS,EAAO,CACd,MAAO,CAAE,QAAO,GAAI,EAAM,CAC5B,CACF"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export type AttemptResult<T> = {
|
|
2
|
+
ok: true;
|
|
3
|
+
value: T;
|
|
4
|
+
} | {
|
|
5
|
+
ok: false;
|
|
6
|
+
error: unknown;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Narrows an `AttemptResult` to the success branch.
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const result = await attempt(() => fetch('/api').then(r => r.json()));
|
|
13
|
+
* if (isOk(result)) console.log(result.value);
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare function isOk<T>(result: AttemptResult<T>): result is {
|
|
17
|
+
ok: true;
|
|
18
|
+
value: T;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Narrows an `AttemptResult` to the failure branch.
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* const result = await attempt(() => fetch('/api').then(r => r.json()));
|
|
25
|
+
* if (isFail(result)) console.error(result.error);
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function isFail<T>(result: AttemptResult<T>): result is {
|
|
29
|
+
ok: false;
|
|
30
|
+
error: unknown;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Executes a function — sync or async — and returns an `AttemptResult` (or
|
|
34
|
+
* `Promise<AttemptResult>` for async factories). Never throws.
|
|
35
|
+
*
|
|
36
|
+
* TypeScript infers the return type from the factory:
|
|
37
|
+
* - sync factory → `AttemptResult<T>`
|
|
38
|
+
* - async factory → `Promise<AttemptResult<T>>`
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* // Sync
|
|
43
|
+
* const parsed = attempt(() => JSON.parse(rawJson));
|
|
44
|
+
* if (parsed.ok) console.log(parsed.value);
|
|
45
|
+
* else console.error(parsed.error);
|
|
46
|
+
*
|
|
47
|
+
* // Async
|
|
48
|
+
* const result = await attempt(() => fetch('/api').then(r => r.json()));
|
|
49
|
+
* if (result.ok) console.log(result.value);
|
|
50
|
+
* else console.error(result.error);
|
|
51
|
+
*
|
|
52
|
+
* // Combined with retry()
|
|
53
|
+
* const result = await attempt(() => retry(fn, { times: 3 }));
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export declare function attempt<T>(fn: () => Promise<T>): Promise<AttemptResult<T>>;
|
|
57
|
+
export declare function attempt<T>(fn: () => T): AttemptResult<T>;
|
|
58
|
+
//# sourceMappingURL=attempt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attempt.d.ts","sourceRoot":"","sources":["../../src/async/attempt.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,CAAC,CAAC,IACvB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GAEtB;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAAC;AAElC;;;;;;;GAOG;AAEH,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,CAElF;AAED;;;;;;;GAOG;AAEH,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAE3F;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5E,wBAAgB,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//#region src/async/attempt.ts
|
|
2
|
+
function e(e) {
|
|
3
|
+
return e.ok === !0;
|
|
4
|
+
}
|
|
5
|
+
function t(e) {
|
|
6
|
+
return e.ok === !1;
|
|
7
|
+
}
|
|
8
|
+
function n(e) {
|
|
9
|
+
try {
|
|
10
|
+
let t = e();
|
|
11
|
+
return typeof t?.then == "function" ? t.then((e) => ({
|
|
12
|
+
ok: !0,
|
|
13
|
+
value: e
|
|
14
|
+
}), (e) => ({
|
|
15
|
+
error: e,
|
|
16
|
+
ok: !1
|
|
17
|
+
})) : {
|
|
18
|
+
ok: !0,
|
|
19
|
+
value: t
|
|
20
|
+
};
|
|
21
|
+
} catch (e) {
|
|
22
|
+
return {
|
|
23
|
+
error: e,
|
|
24
|
+
ok: !1
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { n as attempt, t as isFail, e as isOk };
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=attempt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attempt.js","names":[],"sources":["../../src/async/attempt.ts"],"sourcesContent":["export type AttemptResult<T> =\n | { ok: true; value: T }\n // eslint-disable-next-line perfectionist/sort-object-types\n | { ok: false; error: unknown };\n\n/**\n * Narrows an `AttemptResult` to the success branch.\n * @example\n * ```ts\n * const result = await attempt(() => fetch('/api').then(r => r.json()));\n * if (isOk(result)) console.log(result.value);\n * ```\n */\n\nexport function isOk<T>(result: AttemptResult<T>): result is { ok: true; value: T } {\n return result.ok === true;\n}\n\n/**\n * Narrows an `AttemptResult` to the failure branch.\n * @example\n * ```ts\n * const result = await attempt(() => fetch('/api').then(r => r.json()));\n * if (isFail(result)) console.error(result.error);\n * ```\n */\n// eslint-disable-next-line perfectionist/sort-object-types\nexport function isFail<T>(result: AttemptResult<T>): result is { ok: false; error: unknown } {\n return result.ok === false;\n}\n\n/**\n * Executes a function — sync or async — and returns an `AttemptResult` (or\n * `Promise<AttemptResult>` for async factories). Never throws.\n *\n * TypeScript infers the return type from the factory:\n * - sync factory → `AttemptResult<T>`\n * - async factory → `Promise<AttemptResult<T>>`\n *\n * @example\n * ```ts\n * // Sync\n * const parsed = attempt(() => JSON.parse(rawJson));\n * if (parsed.ok) console.log(parsed.value);\n * else console.error(parsed.error);\n *\n * // Async\n * const result = await attempt(() => fetch('/api').then(r => r.json()));\n * if (result.ok) console.log(result.value);\n * else console.error(result.error);\n *\n * // Combined with retry()\n * const result = await attempt(() => retry(fn, { times: 3 }));\n * ```\n */\nexport function attempt<T>(fn: () => Promise<T>): Promise<AttemptResult<T>>;\nexport function attempt<T>(fn: () => T): AttemptResult<T>;\nexport function attempt<T>(fn: () => T | Promise<T>): AttemptResult<T> | Promise<AttemptResult<T>> {\n try {\n const result = fn();\n\n if (typeof (result as PromiseLike<T>)?.then === 'function') {\n return (result as Promise<T>).then(\n (value) => ({ ok: true as const, value }),\n (error) => ({ error, ok: false as const }),\n );\n }\n\n return { ok: true, value: result as T };\n } catch (error) {\n return { error, ok: false };\n }\n}\n"],"mappings":";AAcA,SAAgB,EAAQ,GAA4D;CAClF,OAAO,EAAO,OAAO;AACvB;AAWA,SAAgB,EAAU,GAAmE;CAC3F,OAAO,EAAO,OAAO;AACvB;AA4BA,SAAgB,EAAW,GAAwE;CACjG,IAAI;EACF,IAAM,IAAS,EAAG;EASlB,OAPI,OAAQ,GAA2B,QAAS,aACtC,EAAsB,MAC3B,OAAW;GAAE,IAAI;GAAe;EAAM,KACtC,OAAW;GAAE;GAAO,IAAI;EAAe,EAC1C,IAGK;GAAE,IAAI;GAAM,OAAO;EAAY;CACxC,SAAS,GAAO;EACd,OAAO;GAAE;GAAO,IAAI;EAAM;CAC5B;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backoff.cjs","names":[],"sources":["../../src/async/backoff.ts"],"sourcesContent":["/**\n * Computes an exponential backoff delay cap for a given zero-based attempt number.\n * Returns `min(1000 × 2ⁿ, maxMs)` — the cap before optional jitter is applied.\n *\n * Multiply the result by `Math.random()` for full-jitter backoff.\n *\n * @example\n * ```ts\n * // Deterministic (sourcerer-style):\n * const delay = backoff(attempt); // 1s, 2s, 4s, … capped at 30s\n *\n * // Full-jitter (courier-style):\n * const delay = Math.random() * backoff(attempt);\n * ```\n *\n * @param attempt - Zero-based attempt index (0 = first retry wait).\n * @param maxMs - Maximum cap in milliseconds. Defaults to 30 000.\n */\nexport function backoff(attempt: number, maxMs = 30_000): number {\n const n = Math.max(0, Number.isNaN(attempt) ? 0 : Math.floor(attempt));\n\n return Math.min(1000 * (n <= 30 ? 1 << n : Math.pow(2, n)), maxMs);\n}\n"],"mappings":"AAkBA,SAAgB,EAAQ,EAAiB,EAAQ,IAAgB,CAC/D,IAAM,EAAI,KAAK,IAAI,EAAG,OAAO,MAAM,CAAO,EAAI,EAAI,KAAK,MAAM,CAAO,CAAC,EAErE,OAAO,KAAK,IAAI,KAAQ,GAAK,GAAK,GAAK,EAAa,GAAG,GAAK,CAAK,CACnE"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes an exponential backoff delay cap for a given zero-based attempt number.
|
|
3
|
+
* Returns `min(1000 × 2ⁿ, maxMs)` — the cap before optional jitter is applied.
|
|
4
|
+
*
|
|
5
|
+
* Multiply the result by `Math.random()` for full-jitter backoff.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* // Deterministic (sourcerer-style):
|
|
10
|
+
* const delay = backoff(attempt); // 1s, 2s, 4s, … capped at 30s
|
|
11
|
+
*
|
|
12
|
+
* // Full-jitter (courier-style):
|
|
13
|
+
* const delay = Math.random() * backoff(attempt);
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @param attempt - Zero-based attempt index (0 = first retry wait).
|
|
17
|
+
* @param maxMs - Maximum cap in milliseconds. Defaults to 30 000.
|
|
18
|
+
*/
|
|
19
|
+
export declare function backoff(attempt: number, maxMs?: number): number;
|
|
20
|
+
//# sourceMappingURL=backoff.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backoff.d.ts","sourceRoot":"","sources":["../../src/async/backoff.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,SAAS,GAAG,MAAM,CAI/D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backoff.js","names":[],"sources":["../../src/async/backoff.ts"],"sourcesContent":["/**\n * Computes an exponential backoff delay cap for a given zero-based attempt number.\n * Returns `min(1000 × 2ⁿ, maxMs)` — the cap before optional jitter is applied.\n *\n * Multiply the result by `Math.random()` for full-jitter backoff.\n *\n * @example\n * ```ts\n * // Deterministic (sourcerer-style):\n * const delay = backoff(attempt); // 1s, 2s, 4s, … capped at 30s\n *\n * // Full-jitter (courier-style):\n * const delay = Math.random() * backoff(attempt);\n * ```\n *\n * @param attempt - Zero-based attempt index (0 = first retry wait).\n * @param maxMs - Maximum cap in milliseconds. Defaults to 30 000.\n */\nexport function backoff(attempt: number, maxMs = 30_000): number {\n const n = Math.max(0, Number.isNaN(attempt) ? 0 : Math.floor(attempt));\n\n return Math.min(1000 * (n <= 30 ? 1 << n : Math.pow(2, n)), maxMs);\n}\n"],"mappings":";AAkBA,SAAgB,EAAQ,GAAiB,IAAQ,KAAgB;CAC/D,IAAM,IAAI,KAAK,IAAI,GAAG,OAAO,MAAM,CAAO,IAAI,IAAI,KAAK,MAAM,CAAO,CAAC;CAErE,OAAO,KAAK,IAAI,OAAQ,KAAK,KAAK,KAAK,IAAa,KAAG,IAAK,CAAK;AACnE"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './abortError';
|
|
2
|
+
export * from './attempt';
|
|
3
|
+
export * from './backoff';
|
|
4
|
+
export * from './parallel';
|
|
5
|
+
export * from './queue';
|
|
6
|
+
export * from './retry';
|
|
7
|
+
export * from './sleep';
|
|
8
|
+
export * from './waitFor';
|
|
9
|
+
//# 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,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("../errors.cjs"),t=require("./abortError.cjs");async function n(n,r,i={}){let{abortOnError:a=!1,limit:o=1/0,signal:s}=i;if(o<1)throw new e.ArsenalValidationError(`parallel: limit must be at least 1, got ${o}`);if(s?.aborted)throw t.abortError(s);if(n.length===0)return[];let c=Array(n.length),l=0,u=a?new AbortController:void 0,d=async()=>{for(;;){if(s?.aborted)throw t.abortError(s);if(u?.signal.aborted||l>=n.length)return;let e=l++;try{c[e]=await r(n[e],e,n)}catch(e){throw u?.abort(),e}}},f=Math.min(o,n.length),p=Array.from({length:f},()=>d());return await Promise.all(p),c}exports.parallel=n;
|
|
2
|
+
//# sourceMappingURL=parallel.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parallel.cjs","names":[],"sources":["../../src/async/parallel.ts"],"sourcesContent":["import { ArsenalValidationError } from '../errors';\nimport { abortError } from './abortError';\n\n/**\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([1, 2, 3, 4, 5], async (n) => {\n * await delay(100);\n * return n * 2;\n * }, { limit: 3 });\n * // [2, 4, 6, 8, 10]\n *\n * // With abort signal\n * const controller = new AbortController();\n * const results = await parallel(items, async (item) => {\n * return processItem(item);\n * }, { limit: 2, signal: controller.signal });\n *\n * // Stop other workers as soon as one item fails\n * await parallel(items, riskyOperation, { abortOnError: true, limit: 3 });\n * ```\n *\n * @param array - Array of items to process\n * @param callback - Async function to process each item\n * @param options - Optional options for concurrency and cancellation\n * @param [options.limit=Infinity] - Maximum number of concurrent operations. Defaults to unbounded.\n * @param [options.signal] - Optional AbortSignal to cancel processing\n * @param [options.abortOnError=false] - When `true`, stops other in-flight workers as soon as any\n * callback throws, instead of letting them keep running to completion unobserved. Default\n * preserves the existing best-effort-completion behavior.\n * @returns Promise resolving to an ordered array of results\n * @throws {ArsenalValidationError} If limit is less than 1\n * @throws {DOMException} If aborted via signal\n */\nexport async function parallel<T, R>(\n array: readonly T[],\n callback: (item: T, index: number, array: readonly T[]) => Promise<R> | R,\n options: { abortOnError?: boolean; limit?: number; signal?: AbortSignal } = {},\n): Promise<R[]> {\n const { abortOnError = false, limit = Infinity, signal } = options;\n\n if (limit < 1) {\n throw new ArsenalValidationError(`parallel: limit must be at least 1, got ${limit}`);\n }\n\n if (signal?.aborted) {\n throw abortError(signal);\n }\n\n if (array.length === 0) {\n return [];\n }\n\n const results: R[] = new Array(array.length);\n let currentIndex = 0;\n const failFastController = abortOnError ? new AbortController() : undefined;\n\n const worker = async (): Promise<void> => {\n while (true) {\n if (signal?.aborted) {\n throw abortError(signal);\n }\n\n if (failFastController?.signal.aborted) {\n return;\n }\n\n if (currentIndex >= array.length) {\n return;\n }\n\n const index = currentIndex++;\n\n try {\n results[index] = await callback(array[index]!, index, array);\n } catch (err) {\n failFastController?.abort();\n throw err;\n }\n }\n };\n\n const workerCount = Math.min(limit, array.length);\n const workers = Array.from({ length: workerCount }, () => worker());\n\n await Promise.all(workers);\n\n return results;\n}\n"],"mappings":"+DAuCA,eAAsB,EACpB,EACA,EACA,EAA4E,CAAC,EAC/D,CACd,GAAM,CAAE,eAAe,GAAO,QAAQ,IAAU,UAAW,EAE3D,GAAI,EAAQ,EACV,MAAM,IAAI,EAAA,uBAAuB,2CAA2C,GAAO,EAGrF,GAAI,GAAQ,QACV,MAAM,EAAA,WAAW,CAAM,EAGzB,GAAI,EAAM,SAAW,EACnB,MAAO,CAAC,EAGV,IAAM,EAAmB,MAAM,EAAM,MAAM,EACvC,EAAe,EACb,EAAqB,EAAe,IAAI,gBAAoB,IAAA,GAE5D,EAAS,SAA2B,CACxC,OAAa,CACX,GAAI,GAAQ,QACV,MAAM,EAAA,WAAW,CAAM,EAOzB,GAJI,GAAoB,OAAO,SAI3B,GAAgB,EAAM,OACxB,OAGF,IAAM,EAAQ,IAEd,GAAI,CACF,EAAQ,GAAS,MAAM,EAAS,EAAM,GAAS,EAAO,CAAK,CAC7D,OAAS,EAAK,CAEZ,MADA,GAAoB,MAAM,EACpB,CACR,CACF,CACF,EAEM,EAAc,KAAK,IAAI,EAAO,EAAM,MAAM,EAC1C,EAAU,MAAM,KAAK,CAAE,OAAQ,CAAY,MAAS,EAAO,CAAC,EAIlE,OAFA,MAAM,QAAQ,IAAI,CAAO,EAElB,CACT"}
|
|
@@ -0,0 +1,42 @@
|
|
|
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([1, 2, 3, 4, 5], async (n) => {
|
|
10
|
+
* await delay(100);
|
|
11
|
+
* return n * 2;
|
|
12
|
+
* }, { limit: 3 });
|
|
13
|
+
* // [2, 4, 6, 8, 10]
|
|
14
|
+
*
|
|
15
|
+
* // With abort signal
|
|
16
|
+
* const controller = new AbortController();
|
|
17
|
+
* const results = await parallel(items, async (item) => {
|
|
18
|
+
* return processItem(item);
|
|
19
|
+
* }, { limit: 2, signal: controller.signal });
|
|
20
|
+
*
|
|
21
|
+
* // Stop other workers as soon as one item fails
|
|
22
|
+
* await parallel(items, riskyOperation, { abortOnError: true, limit: 3 });
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @param array - Array of items to process
|
|
26
|
+
* @param callback - Async function to process each item
|
|
27
|
+
* @param options - Optional options for concurrency and cancellation
|
|
28
|
+
* @param [options.limit=Infinity] - Maximum number of concurrent operations. Defaults to unbounded.
|
|
29
|
+
* @param [options.signal] - Optional AbortSignal to cancel processing
|
|
30
|
+
* @param [options.abortOnError=false] - When `true`, stops other in-flight workers as soon as any
|
|
31
|
+
* callback throws, instead of letting them keep running to completion unobserved. Default
|
|
32
|
+
* preserves the existing best-effort-completion behavior.
|
|
33
|
+
* @returns Promise resolving to an ordered array of results
|
|
34
|
+
* @throws {ArsenalValidationError} If limit is less than 1
|
|
35
|
+
* @throws {DOMException} If aborted via signal
|
|
36
|
+
*/
|
|
37
|
+
export declare function parallel<T, R>(array: readonly T[], callback: (item: T, index: number, array: readonly T[]) => Promise<R> | R, options?: {
|
|
38
|
+
abortOnError?: boolean;
|
|
39
|
+
limit?: number;
|
|
40
|
+
signal?: AbortSignal;
|
|
41
|
+
}): Promise<R[]>;
|
|
42
|
+
//# sourceMappingURL=parallel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parallel.d.ts","sourceRoot":"","sources":["../../src/async/parallel.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,wBAAsB,QAAQ,CAAC,CAAC,EAAE,CAAC,EACjC,KAAK,EAAE,SAAS,CAAC,EAAE,EACnB,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,EACzE,OAAO,GAAE;IAAE,YAAY,CAAC,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,WAAW,CAAA;CAAO,GAC7E,OAAO,CAAC,CAAC,EAAE,CAAC,CAkDd"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ArsenalValidationError as e } from "../errors.js";
|
|
2
|
+
import { abortError as t } from "./abortError.js";
|
|
3
|
+
//#region src/async/parallel.ts
|
|
4
|
+
async function n(n, r, i = {}) {
|
|
5
|
+
let { abortOnError: a = !1, limit: o = Infinity, signal: s } = i;
|
|
6
|
+
if (o < 1) throw new e(`parallel: limit must be at least 1, got ${o}`);
|
|
7
|
+
if (s?.aborted) throw t(s);
|
|
8
|
+
if (n.length === 0) return [];
|
|
9
|
+
let c = Array(n.length), l = 0, u = a ? new AbortController() : void 0, d = async () => {
|
|
10
|
+
for (;;) {
|
|
11
|
+
if (s?.aborted) throw t(s);
|
|
12
|
+
if (u?.signal.aborted || l >= n.length) return;
|
|
13
|
+
let e = l++;
|
|
14
|
+
try {
|
|
15
|
+
c[e] = await r(n[e], e, n);
|
|
16
|
+
} catch (e) {
|
|
17
|
+
throw u?.abort(), e;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}, f = Math.min(o, n.length), p = Array.from({ length: f }, () => d());
|
|
21
|
+
return await Promise.all(p), c;
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { n as parallel };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=parallel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parallel.js","names":[],"sources":["../../src/async/parallel.ts"],"sourcesContent":["import { ArsenalValidationError } from '../errors';\nimport { abortError } from './abortError';\n\n/**\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([1, 2, 3, 4, 5], async (n) => {\n * await delay(100);\n * return n * 2;\n * }, { limit: 3 });\n * // [2, 4, 6, 8, 10]\n *\n * // With abort signal\n * const controller = new AbortController();\n * const results = await parallel(items, async (item) => {\n * return processItem(item);\n * }, { limit: 2, signal: controller.signal });\n *\n * // Stop other workers as soon as one item fails\n * await parallel(items, riskyOperation, { abortOnError: true, limit: 3 });\n * ```\n *\n * @param array - Array of items to process\n * @param callback - Async function to process each item\n * @param options - Optional options for concurrency and cancellation\n * @param [options.limit=Infinity] - Maximum number of concurrent operations. Defaults to unbounded.\n * @param [options.signal] - Optional AbortSignal to cancel processing\n * @param [options.abortOnError=false] - When `true`, stops other in-flight workers as soon as any\n * callback throws, instead of letting them keep running to completion unobserved. Default\n * preserves the existing best-effort-completion behavior.\n * @returns Promise resolving to an ordered array of results\n * @throws {ArsenalValidationError} If limit is less than 1\n * @throws {DOMException} If aborted via signal\n */\nexport async function parallel<T, R>(\n array: readonly T[],\n callback: (item: T, index: number, array: readonly T[]) => Promise<R> | R,\n options: { abortOnError?: boolean; limit?: number; signal?: AbortSignal } = {},\n): Promise<R[]> {\n const { abortOnError = false, limit = Infinity, signal } = options;\n\n if (limit < 1) {\n throw new ArsenalValidationError(`parallel: limit must be at least 1, got ${limit}`);\n }\n\n if (signal?.aborted) {\n throw abortError(signal);\n }\n\n if (array.length === 0) {\n return [];\n }\n\n const results: R[] = new Array(array.length);\n let currentIndex = 0;\n const failFastController = abortOnError ? new AbortController() : undefined;\n\n const worker = async (): Promise<void> => {\n while (true) {\n if (signal?.aborted) {\n throw abortError(signal);\n }\n\n if (failFastController?.signal.aborted) {\n return;\n }\n\n if (currentIndex >= array.length) {\n return;\n }\n\n const index = currentIndex++;\n\n try {\n results[index] = await callback(array[index]!, index, array);\n } catch (err) {\n failFastController?.abort();\n throw err;\n }\n }\n };\n\n const workerCount = Math.min(limit, array.length);\n const workers = Array.from({ length: workerCount }, () => worker());\n\n await Promise.all(workers);\n\n return results;\n}\n"],"mappings":";;;AAuCA,eAAsB,EACpB,GACA,GACA,IAA4E,CAAC,GAC/D;CACd,IAAM,EAAE,kBAAe,IAAO,WAAQ,UAAU,cAAW;CAE3D,IAAI,IAAQ,GACV,MAAM,IAAI,EAAuB,2CAA2C,GAAO;CAGrF,IAAI,GAAQ,SACV,MAAM,EAAW,CAAM;CAGzB,IAAI,EAAM,WAAW,GACnB,OAAO,CAAC;CAGV,IAAM,IAAmB,MAAM,EAAM,MAAM,GACvC,IAAe,GACb,IAAqB,IAAe,IAAI,gBAAgB,IAAI,KAAA,GAE5D,IAAS,YAA2B;EACxC,SAAa;GACX,IAAI,GAAQ,SACV,MAAM,EAAW,CAAM;GAOzB,IAJI,GAAoB,OAAO,WAI3B,KAAgB,EAAM,QACxB;GAGF,IAAM,IAAQ;GAEd,IAAI;IACF,EAAQ,KAAS,MAAM,EAAS,EAAM,IAAS,GAAO,CAAK;GAC7D,SAAS,GAAK;IAEZ,MADA,GAAoB,MAAM,GACpB;GACR;EACF;CACF,GAEM,IAAc,KAAK,IAAI,GAAO,EAAM,MAAM,GAC1C,IAAU,MAAM,KAAK,EAAE,QAAQ,EAAY,SAAS,EAAO,CAAC;CAIlE,OAFA,MAAM,QAAQ,IAAI,CAAO,GAElB;AACT"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("../errors.cjs");function t(t={}){let{concurrency:n=1}=t;if(n<1)throw new e.ArsenalValidationError(`Concurrency must be at least 1`);let r=0,i=!1,a=null,o=null,s=[],c=new Set,l=()=>{r===0&&s.length===0&&o&&(o(),a=null,o=null)},u=e=>{for(let t of c)t(e)},d=()=>{if(!i){for(i=!0;r<n&&s.length>0;){let e=s.shift();r++,Promise.resolve().then(()=>e.fn()).then(t=>{u({ok:!0,value:t}),e.resolve(t)}).catch(t=>{u({error:t,ok:!1}),e.reject(t)}).finally(()=>{r--,d(),l()})}i=!1,l()}};return{get active(){return r},add:(e,t)=>{let{promise:n,reject:r,resolve:i}=Promise.withResolvers(),a=t?.priority??0,o={fn:e,priority:a,reject:r,resolve:i},c=s.length;for(;c>0&&s[c-1].priority<a;)c--;return s.splice(c,0,o),d(),n},clear:e=>{let t=e??Error(`Queue cleared`);for(let e of s.splice(0))e.reject(t);l()},onIdle:()=>{if(r===0&&s.length===0)return Promise.resolve();if(!a){let e=Promise.withResolvers();a=e.promise,o=e.resolve}return a},onSettled:e=>(c.add(e),()=>{c.delete(e)}),get pending(){return s.length},get size(){return r+s.length}}}exports.queue=t;
|
|
2
|
+
//# sourceMappingURL=queue.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue.cjs","names":[],"sources":["../../src/async/queue.ts"],"sourcesContent":["import type { AttemptResult } from './attempt';\n\nimport { ArsenalValidationError } from '../errors';\n\n/**\n * Creates a promise queue that processes promises sequentially with optional concurrency limit.\n *\n * @example\n * ```ts\n * const requestQueue = queue({ concurrency: 2 });\n *\n * requestQueue.add(() => fetch('/api/1'));\n * requestQueue.add(() => fetch('/api/2'));\n * requestQueue.add(() => fetch('/api/3'));\n *\n * await requestQueue.onIdle(); // Wait for all tasks to complete\n * ```\n *\n * @param options - Queue configuration\n * @param options.concurrency - Maximum number of concurrent promises (default: 1)\n * @returns Queue instance with add, onIdle, clear, and onSettled methods\n */\nexport type QueueSettledCallback<T = unknown> = (result: AttemptResult<T>) => void;\n\nexport interface Queue {\n /** Adds a task to the queue. Returns a promise that resolves/rejects with the task result. */\n add<T>(fn: () => Promise<T>, options?: { priority?: number }): Promise<T>;\n /** Clears all pending tasks, rejecting them with the given reason. Running tasks are unaffected. */\n clear(reason?: unknown): void;\n /** Returns a promise that resolves when the queue becomes idle (no active or pending tasks). */\n onIdle(): Promise<void>;\n /** Subscribes to settled results (both resolved and rejected). Returns an unsubscribe function. */\n onSettled<T>(cb: QueueSettledCallback<T>): () => void;\n /** Number of currently running tasks. */\n readonly active: number;\n /** Number of tasks waiting to run. */\n readonly pending: number;\n /** Total tasks (active + pending). */\n readonly size: number;\n}\n\nexport function queue(options: { concurrency?: number } = {}): Queue {\n const { concurrency = 1 } = options;\n\n if (concurrency < 1) throw new ArsenalValidationError('Concurrency must be at least 1');\n\n let activeCount = 0;\n let isDraining = false;\n let idlePromise: Promise<void> | null = null;\n let idleResolve: (() => void) | null = null;\n\n const tasks: Array<{\n fn: () => Promise<unknown>;\n priority: number;\n reject: (error: unknown) => void;\n resolve: (value: unknown) => void;\n }> = [];\n\n const settledListeners = new Set<QueueSettledCallback>();\n\n const resolveIdle = (): void => {\n if (activeCount === 0 && tasks.length === 0 && idleResolve) {\n idleResolve();\n idlePromise = null;\n idleResolve = null;\n }\n };\n\n const notifySettled = (result: AttemptResult<unknown>): void => {\n for (const cb of settledListeners) {\n cb(result);\n }\n };\n\n const drain = (): void => {\n if (isDraining) {\n return;\n }\n\n isDraining = true;\n\n while (activeCount < concurrency && tasks.length > 0) {\n const task = tasks.shift()!;\n\n activeCount++;\n\n void Promise.resolve()\n .then(() => task.fn())\n .then((v) => {\n notifySettled({ ok: true, value: v });\n task.resolve(v);\n })\n .catch((e: unknown) => {\n notifySettled({ error: e, ok: false });\n task.reject(e);\n })\n .finally(() => {\n activeCount--;\n drain();\n resolveIdle();\n });\n }\n\n isDraining = false;\n resolveIdle();\n };\n\n return {\n /**\n * Returns the number of currently running tasks.\n */\n get active(): number {\n return activeCount;\n },\n\n /**\n * Adds a promise-returning function to the queue.\n * Tasks with a higher `priority` number run before lower-priority tasks.\n * Tasks with equal priority run in insertion order (FIFO).\n *\n * @param fn - The async function to queue.\n * @param options.priority - Task priority. Higher numbers run first. Default: 0.\n */\n add: <T>(fn: () => Promise<T>, options?: { priority?: number }): Promise<T> => {\n const { promise, reject, resolve } = Promise.withResolvers<T>();\n const priority = options?.priority ?? 0;\n\n const task = {\n fn: fn as () => Promise<unknown>,\n priority,\n reject,\n resolve: resolve as (value: unknown) => void,\n };\n\n let i = tasks.length;\n\n while (i > 0 && tasks[i - 1]!.priority < priority) {\n i--;\n }\n\n tasks.splice(i, 0, task);\n drain();\n\n return promise;\n },\n\n /**\n * Clears all pending tasks from the queue and rejects them.\n * Running tasks are not affected.\n * @param reason - The error reason for the rejection (defaults to 'Queue cleared')\n */\n clear: (reason?: unknown): void => {\n const clearReason = reason ?? new Error('Queue cleared');\n\n for (const task of tasks.splice(0)) {\n task.reject(clearReason);\n }\n\n resolveIdle();\n },\n\n /**\n * Returns a promise that resolves when the queue becomes idle.\n */\n onIdle: (): Promise<void> => {\n if (activeCount === 0 && tasks.length === 0) {\n return Promise.resolve();\n }\n\n if (!idlePromise) {\n const deferred = Promise.withResolvers<void>();\n\n idlePromise = deferred.promise;\n idleResolve = deferred.resolve;\n }\n\n return idlePromise;\n },\n\n /**\n * Subscribes to settled task results (both resolved and rejected).\n * The callback fires once per task, in completion order.\n * Returns an unsubscribe function.\n *\n * Unlike a `for await` loop, multiple subscribers are supported and\n * no results are accumulated in memory.\n *\n * @example\n * ```ts\n * const q = queue({ concurrency: 2 });\n * const unsub = q.onSettled((result) => {\n * if (result.ok) console.log(result.value);\n * else console.error(result.error);\n * });\n *\n * q.add(() => fetchUser(1));\n * q.add(() => fetchUser(2));\n *\n * await q.onIdle();\n * unsub(); // stop listening\n * ```\n */\n onSettled: <T = unknown>(cb: QueueSettledCallback<T>): (() => void) => {\n settledListeners.add(cb as QueueSettledCallback);\n\n return () => {\n settledListeners.delete(cb as QueueSettledCallback);\n };\n },\n\n /**\n * Returns the number of tasks waiting to run (queued but not yet started).\n */\n get pending(): number {\n return tasks.length;\n },\n\n /**\n * Returns the total number of tasks (active + pending).\n */\n get size(): number {\n return activeCount + tasks.length;\n },\n };\n}\n"],"mappings":"iCAyCA,SAAgB,EAAM,EAAoC,CAAC,EAAU,CACnE,GAAM,CAAE,cAAc,GAAM,EAE5B,GAAI,EAAc,EAAG,MAAM,IAAI,EAAA,uBAAuB,gCAAgC,EAEtF,IAAI,EAAc,EACd,EAAa,GACb,EAAoC,KACpC,EAAmC,KAEjC,EAKD,CAAC,EAEA,EAAmB,IAAI,IAEvB,MAA0B,CAC1B,IAAgB,GAAK,EAAM,SAAW,GAAK,IAC7C,EAAY,EACZ,EAAc,KACd,EAAc,KAElB,EAEM,EAAiB,GAAyC,CAC9D,IAAK,IAAM,KAAM,EACf,EAAG,CAAM,CAEb,EAEM,MAAoB,CACpB,MAMJ,KAFA,EAAa,GAEN,EAAc,GAAe,EAAM,OAAS,GAAG,CACpD,IAAM,EAAO,EAAM,MAAM,EAEzB,IAEA,QAAa,QAAQ,CAAC,CACnB,SAAW,EAAK,GAAG,CAAC,CAAC,CACrB,KAAM,GAAM,CACX,EAAc,CAAE,GAAI,GAAM,MAAO,CAAE,CAAC,EACpC,EAAK,QAAQ,CAAC,CAChB,CAAC,CAAC,CACD,MAAO,GAAe,CACrB,EAAc,CAAE,MAAO,EAAG,GAAI,EAAM,CAAC,EACrC,EAAK,OAAO,CAAC,CACf,CAAC,CAAC,CACD,YAAc,CACb,IACA,EAAM,EACN,EAAY,CACd,CAAC,CACL,CAEA,EAAa,GACb,EAAY,CAHZ,CAIF,EAEA,MAAO,CAIL,IAAI,QAAiB,CACnB,OAAO,CACT,EAUA,KAAS,EAAsB,IAAgD,CAC7E,GAAM,CAAE,UAAS,SAAQ,WAAY,QAAQ,cAAiB,EACxD,EAAW,GAAS,UAAY,EAEhC,EAAO,CACP,KACJ,WACA,SACS,SACX,EAEI,EAAI,EAAM,OAEd,KAAO,EAAI,GAAK,EAAM,EAAI,EAAE,CAAE,SAAW,GACvC,IAMF,OAHA,EAAM,OAAO,EAAG,EAAG,CAAI,EACvB,EAAM,EAEC,CACT,EAOA,MAAQ,GAA2B,CACjC,IAAM,EAAc,GAAc,MAAM,eAAe,EAEvD,IAAK,IAAM,KAAQ,EAAM,OAAO,CAAC,EAC/B,EAAK,OAAO,CAAW,EAGzB,EAAY,CACd,EAKA,WAA6B,CAC3B,GAAI,IAAgB,GAAK,EAAM,SAAW,EACxC,OAAO,QAAQ,QAAQ,EAGzB,GAAI,CAAC,EAAa,CAChB,IAAM,EAAW,QAAQ,cAAoB,EAE7C,EAAc,EAAS,QACvB,EAAc,EAAS,OACzB,CAEA,OAAO,CACT,EAyBA,UAAyB,IACvB,EAAiB,IAAI,CAA0B,MAElC,CACX,EAAiB,OAAO,CAA0B,CACpD,GAMF,IAAI,SAAkB,CACpB,OAAO,EAAM,MACf,EAKA,IAAI,MAAe,CACjB,OAAO,EAAc,EAAM,MAC7B,CACF,CACF"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { AttemptResult } from './attempt';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a promise queue that processes promises sequentially with optional concurrency limit.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* const requestQueue = queue({ concurrency: 2 });
|
|
8
|
+
*
|
|
9
|
+
* requestQueue.add(() => fetch('/api/1'));
|
|
10
|
+
* requestQueue.add(() => fetch('/api/2'));
|
|
11
|
+
* requestQueue.add(() => fetch('/api/3'));
|
|
12
|
+
*
|
|
13
|
+
* await requestQueue.onIdle(); // Wait for all tasks to complete
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @param options - Queue configuration
|
|
17
|
+
* @param options.concurrency - Maximum number of concurrent promises (default: 1)
|
|
18
|
+
* @returns Queue instance with add, onIdle, clear, and onSettled methods
|
|
19
|
+
*/
|
|
20
|
+
export type QueueSettledCallback<T = unknown> = (result: AttemptResult<T>) => void;
|
|
21
|
+
export interface Queue {
|
|
22
|
+
/** Adds a task to the queue. Returns a promise that resolves/rejects with the task result. */
|
|
23
|
+
add<T>(fn: () => Promise<T>, options?: {
|
|
24
|
+
priority?: number;
|
|
25
|
+
}): Promise<T>;
|
|
26
|
+
/** Clears all pending tasks, rejecting them with the given reason. Running tasks are unaffected. */
|
|
27
|
+
clear(reason?: unknown): void;
|
|
28
|
+
/** Returns a promise that resolves when the queue becomes idle (no active or pending tasks). */
|
|
29
|
+
onIdle(): Promise<void>;
|
|
30
|
+
/** Subscribes to settled results (both resolved and rejected). Returns an unsubscribe function. */
|
|
31
|
+
onSettled<T>(cb: QueueSettledCallback<T>): () => void;
|
|
32
|
+
/** Number of currently running tasks. */
|
|
33
|
+
readonly active: number;
|
|
34
|
+
/** Number of tasks waiting to run. */
|
|
35
|
+
readonly pending: number;
|
|
36
|
+
/** Total tasks (active + pending). */
|
|
37
|
+
readonly size: number;
|
|
38
|
+
}
|
|
39
|
+
export declare function queue(options?: {
|
|
40
|
+
concurrency?: number;
|
|
41
|
+
}): Queue;
|
|
42
|
+
//# sourceMappingURL=queue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../../src/async/queue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAI/C;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,oBAAoB,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;AAEnF,MAAM,WAAW,KAAK;IACpB,8FAA8F;IAC9F,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAC1E,oGAAoG;IACpG,KAAK,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC9B,gGAAgG;IAChG,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACxB,mGAAmG;IACnG,SAAS,CAAC,CAAC,EAAE,EAAE,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,CAAC;IACtD,yCAAyC;IACzC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,sCAAsC;IACtC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,sCAAsC;IACtC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,wBAAgB,KAAK,CAAC,OAAO,GAAE;IAAE,WAAW,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,KAAK,CAuLnE"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { ArsenalValidationError as e } from "../errors.js";
|
|
2
|
+
//#region src/async/queue.ts
|
|
3
|
+
function t(t = {}) {
|
|
4
|
+
let { concurrency: n = 1 } = t;
|
|
5
|
+
if (n < 1) throw new e("Concurrency must be at least 1");
|
|
6
|
+
let r = 0, i = !1, a = null, o = null, s = [], c = /* @__PURE__ */ new Set(), l = () => {
|
|
7
|
+
r === 0 && s.length === 0 && o && (o(), a = null, o = null);
|
|
8
|
+
}, u = (e) => {
|
|
9
|
+
for (let t of c) t(e);
|
|
10
|
+
}, d = () => {
|
|
11
|
+
if (!i) {
|
|
12
|
+
for (i = !0; r < n && s.length > 0;) {
|
|
13
|
+
let e = s.shift();
|
|
14
|
+
r++, Promise.resolve().then(() => e.fn()).then((t) => {
|
|
15
|
+
u({
|
|
16
|
+
ok: !0,
|
|
17
|
+
value: t
|
|
18
|
+
}), e.resolve(t);
|
|
19
|
+
}).catch((t) => {
|
|
20
|
+
u({
|
|
21
|
+
error: t,
|
|
22
|
+
ok: !1
|
|
23
|
+
}), e.reject(t);
|
|
24
|
+
}).finally(() => {
|
|
25
|
+
r--, d(), l();
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
i = !1, l();
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
get active() {
|
|
33
|
+
return r;
|
|
34
|
+
},
|
|
35
|
+
add: (e, t) => {
|
|
36
|
+
let { promise: n, reject: r, resolve: i } = Promise.withResolvers(), a = t?.priority ?? 0, o = {
|
|
37
|
+
fn: e,
|
|
38
|
+
priority: a,
|
|
39
|
+
reject: r,
|
|
40
|
+
resolve: i
|
|
41
|
+
}, c = s.length;
|
|
42
|
+
for (; c > 0 && s[c - 1].priority < a;) c--;
|
|
43
|
+
return s.splice(c, 0, o), d(), n;
|
|
44
|
+
},
|
|
45
|
+
clear: (e) => {
|
|
46
|
+
let t = e ?? /* @__PURE__ */ Error("Queue cleared");
|
|
47
|
+
for (let e of s.splice(0)) e.reject(t);
|
|
48
|
+
l();
|
|
49
|
+
},
|
|
50
|
+
onIdle: () => {
|
|
51
|
+
if (r === 0 && s.length === 0) return Promise.resolve();
|
|
52
|
+
if (!a) {
|
|
53
|
+
let e = Promise.withResolvers();
|
|
54
|
+
a = e.promise, o = e.resolve;
|
|
55
|
+
}
|
|
56
|
+
return a;
|
|
57
|
+
},
|
|
58
|
+
onSettled: (e) => (c.add(e), () => {
|
|
59
|
+
c.delete(e);
|
|
60
|
+
}),
|
|
61
|
+
get pending() {
|
|
62
|
+
return s.length;
|
|
63
|
+
},
|
|
64
|
+
get size() {
|
|
65
|
+
return r + s.length;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
//#endregion
|
|
70
|
+
export { t as queue };
|
|
71
|
+
|
|
72
|
+
//# sourceMappingURL=queue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue.js","names":[],"sources":["../../src/async/queue.ts"],"sourcesContent":["import type { AttemptResult } from './attempt';\n\nimport { ArsenalValidationError } from '../errors';\n\n/**\n * Creates a promise queue that processes promises sequentially with optional concurrency limit.\n *\n * @example\n * ```ts\n * const requestQueue = queue({ concurrency: 2 });\n *\n * requestQueue.add(() => fetch('/api/1'));\n * requestQueue.add(() => fetch('/api/2'));\n * requestQueue.add(() => fetch('/api/3'));\n *\n * await requestQueue.onIdle(); // Wait for all tasks to complete\n * ```\n *\n * @param options - Queue configuration\n * @param options.concurrency - Maximum number of concurrent promises (default: 1)\n * @returns Queue instance with add, onIdle, clear, and onSettled methods\n */\nexport type QueueSettledCallback<T = unknown> = (result: AttemptResult<T>) => void;\n\nexport interface Queue {\n /** Adds a task to the queue. Returns a promise that resolves/rejects with the task result. */\n add<T>(fn: () => Promise<T>, options?: { priority?: number }): Promise<T>;\n /** Clears all pending tasks, rejecting them with the given reason. Running tasks are unaffected. */\n clear(reason?: unknown): void;\n /** Returns a promise that resolves when the queue becomes idle (no active or pending tasks). */\n onIdle(): Promise<void>;\n /** Subscribes to settled results (both resolved and rejected). Returns an unsubscribe function. */\n onSettled<T>(cb: QueueSettledCallback<T>): () => void;\n /** Number of currently running tasks. */\n readonly active: number;\n /** Number of tasks waiting to run. */\n readonly pending: number;\n /** Total tasks (active + pending). */\n readonly size: number;\n}\n\nexport function queue(options: { concurrency?: number } = {}): Queue {\n const { concurrency = 1 } = options;\n\n if (concurrency < 1) throw new ArsenalValidationError('Concurrency must be at least 1');\n\n let activeCount = 0;\n let isDraining = false;\n let idlePromise: Promise<void> | null = null;\n let idleResolve: (() => void) | null = null;\n\n const tasks: Array<{\n fn: () => Promise<unknown>;\n priority: number;\n reject: (error: unknown) => void;\n resolve: (value: unknown) => void;\n }> = [];\n\n const settledListeners = new Set<QueueSettledCallback>();\n\n const resolveIdle = (): void => {\n if (activeCount === 0 && tasks.length === 0 && idleResolve) {\n idleResolve();\n idlePromise = null;\n idleResolve = null;\n }\n };\n\n const notifySettled = (result: AttemptResult<unknown>): void => {\n for (const cb of settledListeners) {\n cb(result);\n }\n };\n\n const drain = (): void => {\n if (isDraining) {\n return;\n }\n\n isDraining = true;\n\n while (activeCount < concurrency && tasks.length > 0) {\n const task = tasks.shift()!;\n\n activeCount++;\n\n void Promise.resolve()\n .then(() => task.fn())\n .then((v) => {\n notifySettled({ ok: true, value: v });\n task.resolve(v);\n })\n .catch((e: unknown) => {\n notifySettled({ error: e, ok: false });\n task.reject(e);\n })\n .finally(() => {\n activeCount--;\n drain();\n resolveIdle();\n });\n }\n\n isDraining = false;\n resolveIdle();\n };\n\n return {\n /**\n * Returns the number of currently running tasks.\n */\n get active(): number {\n return activeCount;\n },\n\n /**\n * Adds a promise-returning function to the queue.\n * Tasks with a higher `priority` number run before lower-priority tasks.\n * Tasks with equal priority run in insertion order (FIFO).\n *\n * @param fn - The async function to queue.\n * @param options.priority - Task priority. Higher numbers run first. Default: 0.\n */\n add: <T>(fn: () => Promise<T>, options?: { priority?: number }): Promise<T> => {\n const { promise, reject, resolve } = Promise.withResolvers<T>();\n const priority = options?.priority ?? 0;\n\n const task = {\n fn: fn as () => Promise<unknown>,\n priority,\n reject,\n resolve: resolve as (value: unknown) => void,\n };\n\n let i = tasks.length;\n\n while (i > 0 && tasks[i - 1]!.priority < priority) {\n i--;\n }\n\n tasks.splice(i, 0, task);\n drain();\n\n return promise;\n },\n\n /**\n * Clears all pending tasks from the queue and rejects them.\n * Running tasks are not affected.\n * @param reason - The error reason for the rejection (defaults to 'Queue cleared')\n */\n clear: (reason?: unknown): void => {\n const clearReason = reason ?? new Error('Queue cleared');\n\n for (const task of tasks.splice(0)) {\n task.reject(clearReason);\n }\n\n resolveIdle();\n },\n\n /**\n * Returns a promise that resolves when the queue becomes idle.\n */\n onIdle: (): Promise<void> => {\n if (activeCount === 0 && tasks.length === 0) {\n return Promise.resolve();\n }\n\n if (!idlePromise) {\n const deferred = Promise.withResolvers<void>();\n\n idlePromise = deferred.promise;\n idleResolve = deferred.resolve;\n }\n\n return idlePromise;\n },\n\n /**\n * Subscribes to settled task results (both resolved and rejected).\n * The callback fires once per task, in completion order.\n * Returns an unsubscribe function.\n *\n * Unlike a `for await` loop, multiple subscribers are supported and\n * no results are accumulated in memory.\n *\n * @example\n * ```ts\n * const q = queue({ concurrency: 2 });\n * const unsub = q.onSettled((result) => {\n * if (result.ok) console.log(result.value);\n * else console.error(result.error);\n * });\n *\n * q.add(() => fetchUser(1));\n * q.add(() => fetchUser(2));\n *\n * await q.onIdle();\n * unsub(); // stop listening\n * ```\n */\n onSettled: <T = unknown>(cb: QueueSettledCallback<T>): (() => void) => {\n settledListeners.add(cb as QueueSettledCallback);\n\n return () => {\n settledListeners.delete(cb as QueueSettledCallback);\n };\n },\n\n /**\n * Returns the number of tasks waiting to run (queued but not yet started).\n */\n get pending(): number {\n return tasks.length;\n },\n\n /**\n * Returns the total number of tasks (active + pending).\n */\n get size(): number {\n return activeCount + tasks.length;\n },\n };\n}\n"],"mappings":";;AAyCA,SAAgB,EAAM,IAAoC,CAAC,GAAU;CACnE,IAAM,EAAE,iBAAc,MAAM;CAE5B,IAAI,IAAc,GAAG,MAAM,IAAI,EAAuB,gCAAgC;CAEtF,IAAI,IAAc,GACd,IAAa,IACb,IAAoC,MACpC,IAAmC,MAEjC,IAKD,CAAC,GAEA,oBAAmB,IAAI,IAA0B,GAEjD,UAA0B;EAC9B,AAAI,MAAgB,KAAK,EAAM,WAAW,KAAK,MAC7C,EAAY,GACZ,IAAc,MACd,IAAc;CAElB,GAEM,KAAiB,MAAyC;EAC9D,KAAK,IAAM,KAAM,GACf,EAAG,CAAM;CAEb,GAEM,UAAoB;EACpB,QAMJ;QAFA,IAAa,IAEN,IAAc,KAAe,EAAM,SAAS,IAAG;IACpD,IAAM,IAAO,EAAM,MAAM;IAIzB,AAFA,KAEA,QAAa,QAAQ,CAAC,CACnB,WAAW,EAAK,GAAG,CAAC,CAAC,CACrB,MAAM,MAAM;KAEX,AADA,EAAc;MAAE,IAAI;MAAM,OAAO;KAAE,CAAC,GACpC,EAAK,QAAQ,CAAC;IAChB,CAAC,CAAC,CACD,OAAO,MAAe;KAErB,AADA,EAAc;MAAE,OAAO;MAAG,IAAI;KAAM,CAAC,GACrC,EAAK,OAAO,CAAC;IACf,CAAC,CAAC,CACD,cAAc;KAGb,AAFA,KACA,EAAM,GACN,EAAY;IACd,CAAC;GACL;GAGA,AADA,IAAa,IACb,EAAY;EAHZ;CAIF;CAEA,OAAO;EAIL,IAAI,SAAiB;GACnB,OAAO;EACT;EAUA,MAAS,GAAsB,MAAgD;GAC7E,IAAM,EAAE,YAAS,WAAQ,eAAY,QAAQ,cAAiB,GACxD,IAAW,GAAS,YAAY,GAEhC,IAAO;IACP;IACJ;IACA;IACS;GACX,GAEI,IAAI,EAAM;GAEd,OAAO,IAAI,KAAK,EAAM,IAAI,EAAE,CAAE,WAAW,IACvC;GAMF,OAHA,EAAM,OAAO,GAAG,GAAG,CAAI,GACvB,EAAM,GAEC;EACT;EAOA,QAAQ,MAA2B;GACjC,IAAM,IAAc,KAAU,gBAAI,MAAM,eAAe;GAEvD,KAAK,IAAM,KAAQ,EAAM,OAAO,CAAC,GAC/B,EAAK,OAAO,CAAW;GAGzB,EAAY;EACd;EAKA,cAA6B;GAC3B,IAAI,MAAgB,KAAK,EAAM,WAAW,GACxC,OAAO,QAAQ,QAAQ;GAGzB,IAAI,CAAC,GAAa;IAChB,IAAM,IAAW,QAAQ,cAAoB;IAG7C,AADA,IAAc,EAAS,SACvB,IAAc,EAAS;GACzB;GAEA,OAAO;EACT;EAyBA,YAAyB,OACvB,EAAiB,IAAI,CAA0B,SAElC;GACX,EAAiB,OAAO,CAA0B;EACpD;EAMF,IAAI,UAAkB;GACpB,OAAO,EAAM;EACf;EAKA,IAAI,OAAe;GACjB,OAAO,IAAc,EAAM;EAC7B;CACF;AACF"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("../errors.cjs"),t=require("./abortError.cjs"),n=require("./sleep.cjs");function r(e,t){let n=[e===void 0?void 0:AbortSignal.timeout(e),t].filter(e=>e!=null);if(n.length!==0)return n.length===1?n[0]:AbortSignal.any(n)}async function i(i,{delay:a=250,onError:o,shouldRetry:s,signal:c,timeout:l,times:u=3}={}){if(!Number.isInteger(u)||u<1)throw new e.ArsenalValidationError(`retry: times must be a positive integer, got ${u}`);for(let e=1;e<=u;e++){if(c?.aborted)throw t.abortError(c);let d=r(l,c);try{return await i(d)}catch(t){if(e===u||s&&!s(t,e-1))throw o?.(t),t;let r=typeof a==`function`?a(e-1):a;r>0&&await n.sleep(r,c)}}}exports.retry=i;
|
|
2
|
+
//# sourceMappingURL=retry.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.cjs","names":[],"sources":["../../src/async/retry.ts"],"sourcesContent":["import { ArsenalValidationError } from '../errors';\nimport { abortError } from './abortError';\nimport { sleep } from './sleep';\n\nexport type RetryOptions = {\n delay?: number | ((attempt: number) => number);\n onError?: (error: unknown) => void;\n shouldRetry?: (error: unknown, attempt: number) => boolean;\n signal?: AbortSignal;\n timeout?: number;\n times?: number;\n};\n\nfunction buildSignal(timeout: number | undefined, signal: AbortSignal | undefined): AbortSignal | undefined {\n const parts = [timeout !== undefined ? AbortSignal.timeout(timeout) : undefined, signal].filter(\n (s): s is AbortSignal => s != null,\n );\n\n if (parts.length === 0) return undefined;\n\n if (parts.length === 1) return parts[0];\n\n return AbortSignal.any(parts);\n}\n\n/**\n * Retries an async function with optional per-attempt timeout, delay strategy, and abort support.\n * The function receives a merged AbortSignal from the per-attempt timeout and any external signal.\n * On total failure, throws the last error (use `attempt()` to get an `AttemptResult` without throwing).\n *\n * @example\n * ```ts\n * // Basic retry\n * const data = await retry(() => fetch('/api').then(r => r.json()), { times: 3 });\n *\n * // With per-attempt timeout and cancellation\n * const data = await retry(\n * async (signal) => fetch('/api', { signal }).then(r => r.json()),\n * { times: 3, timeout: 5000 },\n * );\n *\n * // As AttemptResult (never throws) — combine with attempt()\n * const result = await attempt(() => retry(fn, { times: 3 }));\n * ```\n *\n * @param fn - Async function to retry. Receives a merged AbortSignal when timeout or signal is set.\n * @param options - Retry configuration.\n * @param [options.times=3] - Total attempts including the first.\n * @param [options.delay=250] - Delay between retries in ms, or a function of (attemptIndex).\n * @param [options.timeout] - Per-attempt timeout in milliseconds.\n * @param [options.signal] - External AbortSignal to cancel all retries.\n * @param [options.shouldRetry] - Predicate called after each non-final failure.\n * Receives the error and the number of failures so far (0-indexed: `0` on the first failure,\n * `1` on the second, etc.). Return `false` to abort immediately. **Not called on the final attempt**\n * (use `onError` to observe the final error unconditionally).\n * @param [options.onError] - Called with the last error before rethrowing — both on final attempt exhaustion\n * and when `shouldRetry` returns `false` to abort early.\n * @returns The resolved value.\n * @throws {ArsenalValidationError} If `times` is not a positive integer.\n * @throws The last error if all attempts fail.\n */\nexport async function retry<T>(\n fn: (signal?: AbortSignal) => Promise<T>,\n { delay = 250, onError, shouldRetry, signal, timeout, times = 3 }: RetryOptions = {},\n): Promise<T> {\n if (!Number.isInteger(times) || times < 1) {\n throw new ArsenalValidationError(`retry: times must be a positive integer, got ${times}`);\n }\n\n for (let tryCount = 1; tryCount <= times; tryCount++) {\n if (signal?.aborted) throw abortError(signal);\n\n const callSignal = buildSignal(timeout, signal);\n\n try {\n return await fn(callSignal);\n } catch (err) {\n if (tryCount === times) {\n onError?.(err);\n throw err;\n }\n\n if (shouldRetry && !shouldRetry(err, tryCount - 1)) {\n onError?.(err);\n throw err;\n }\n\n const ms = typeof delay === 'function' ? delay(tryCount - 1) : delay;\n\n if (ms > 0) await sleep(ms, signal);\n }\n }\n\n /* unreachable — the loop always returns or throws before exhausting all attempts */\n return undefined as never;\n}\n"],"mappings":"wFAaA,SAAS,EAAY,EAA6B,EAA0D,CAC1G,IAAM,EAAQ,CAAC,IAAY,IAAA,GAA2C,IAAA,GAA/B,YAAY,QAAQ,CAAO,EAAe,CAAM,CAAC,CAAC,OACtF,GAAwB,GAAK,IAChC,EAEI,KAAM,SAAW,EAIrB,OAFI,EAAM,SAAW,EAAU,EAAM,GAE9B,YAAY,IAAI,CAAK,CAC9B,CAsCA,eAAsB,EACpB,EACA,CAAE,QAAQ,IAAK,UAAS,cAAa,SAAQ,UAAS,QAAQ,GAAoB,CAAC,EACvE,CACZ,GAAI,CAAC,OAAO,UAAU,CAAK,GAAK,EAAQ,EACtC,MAAM,IAAI,EAAA,uBAAuB,gDAAgD,GAAO,EAG1F,IAAK,IAAI,EAAW,EAAG,GAAY,EAAO,IAAY,CACpD,GAAI,GAAQ,QAAS,MAAM,EAAA,WAAW,CAAM,EAE5C,IAAM,EAAa,EAAY,EAAS,CAAM,EAE9C,GAAI,CACF,OAAO,MAAM,EAAG,CAAU,CAC5B,OAAS,EAAK,CAMZ,GALI,IAAa,GAKb,GAAe,CAAC,EAAY,EAAK,EAAW,CAAC,EAE/C,MADA,IAAU,CAAG,EACP,EAGR,IAAM,EAAK,OAAO,GAAU,WAAa,EAAM,EAAW,CAAC,EAAI,EAE3D,EAAK,GAAG,MAAM,EAAA,MAAM,EAAI,CAAM,CACpC,CACF,CAIF"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export type RetryOptions = {
|
|
2
|
+
delay?: number | ((attempt: number) => number);
|
|
3
|
+
onError?: (error: unknown) => void;
|
|
4
|
+
shouldRetry?: (error: unknown, attempt: number) => boolean;
|
|
5
|
+
signal?: AbortSignal;
|
|
6
|
+
timeout?: number;
|
|
7
|
+
times?: number;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Retries an async function with optional per-attempt timeout, delay strategy, and abort support.
|
|
11
|
+
* The function receives a merged AbortSignal from the per-attempt timeout and any external signal.
|
|
12
|
+
* On total failure, throws the last error (use `attempt()` to get an `AttemptResult` without throwing).
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* // Basic retry
|
|
17
|
+
* const data = await retry(() => fetch('/api').then(r => r.json()), { times: 3 });
|
|
18
|
+
*
|
|
19
|
+
* // With per-attempt timeout and cancellation
|
|
20
|
+
* const data = await retry(
|
|
21
|
+
* async (signal) => fetch('/api', { signal }).then(r => r.json()),
|
|
22
|
+
* { times: 3, timeout: 5000 },
|
|
23
|
+
* );
|
|
24
|
+
*
|
|
25
|
+
* // As AttemptResult (never throws) — combine with attempt()
|
|
26
|
+
* const result = await attempt(() => retry(fn, { times: 3 }));
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @param fn - Async function to retry. Receives a merged AbortSignal when timeout or signal is set.
|
|
30
|
+
* @param options - Retry configuration.
|
|
31
|
+
* @param [options.times=3] - Total attempts including the first.
|
|
32
|
+
* @param [options.delay=250] - Delay between retries in ms, or a function of (attemptIndex).
|
|
33
|
+
* @param [options.timeout] - Per-attempt timeout in milliseconds.
|
|
34
|
+
* @param [options.signal] - External AbortSignal to cancel all retries.
|
|
35
|
+
* @param [options.shouldRetry] - Predicate called after each non-final failure.
|
|
36
|
+
* Receives the error and the number of failures so far (0-indexed: `0` on the first failure,
|
|
37
|
+
* `1` on the second, etc.). Return `false` to abort immediately. **Not called on the final attempt**
|
|
38
|
+
* (use `onError` to observe the final error unconditionally).
|
|
39
|
+
* @param [options.onError] - Called with the last error before rethrowing — both on final attempt exhaustion
|
|
40
|
+
* and when `shouldRetry` returns `false` to abort early.
|
|
41
|
+
* @returns The resolved value.
|
|
42
|
+
* @throws {ArsenalValidationError} If `times` is not a positive integer.
|
|
43
|
+
* @throws The last error if all attempts fail.
|
|
44
|
+
*/
|
|
45
|
+
export declare function retry<T>(fn: (signal?: AbortSignal) => Promise<T>, { delay, onError, shouldRetry, signal, timeout, times }?: RetryOptions): Promise<T>;
|
|
46
|
+
//# sourceMappingURL=retry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../src/async/retry.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,YAAY,GAAG;IACzB,KAAK,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC,CAAC;IAC/C,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IACnC,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC;IAC3D,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAcF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,wBAAsB,KAAK,CAAC,CAAC,EAC3B,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,EACxC,EAAE,KAAW,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,KAAS,EAAE,GAAE,YAAiB,GACnF,OAAO,CAAC,CAAC,CAAC,CA+BZ"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ArsenalValidationError as e } from "../errors.js";
|
|
2
|
+
import { abortError as t } from "./abortError.js";
|
|
3
|
+
import { sleep as n } from "./sleep.js";
|
|
4
|
+
//#region src/async/retry.ts
|
|
5
|
+
function r(e, t) {
|
|
6
|
+
let n = [e === void 0 ? void 0 : AbortSignal.timeout(e), t].filter((e) => e != null);
|
|
7
|
+
if (n.length !== 0) return n.length === 1 ? n[0] : AbortSignal.any(n);
|
|
8
|
+
}
|
|
9
|
+
async function i(i, { delay: a = 250, onError: o, shouldRetry: s, signal: c, timeout: l, times: u = 3 } = {}) {
|
|
10
|
+
if (!Number.isInteger(u) || u < 1) throw new e(`retry: times must be a positive integer, got ${u}`);
|
|
11
|
+
for (let e = 1; e <= u; e++) {
|
|
12
|
+
if (c?.aborted) throw t(c);
|
|
13
|
+
let d = r(l, c);
|
|
14
|
+
try {
|
|
15
|
+
return await i(d);
|
|
16
|
+
} catch (t) {
|
|
17
|
+
if (e === u || s && !s(t, e - 1)) throw o?.(t), t;
|
|
18
|
+
let r = typeof a == "function" ? a(e - 1) : a;
|
|
19
|
+
r > 0 && await n(r, c);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { i as retry };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=retry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.js","names":[],"sources":["../../src/async/retry.ts"],"sourcesContent":["import { ArsenalValidationError } from '../errors';\nimport { abortError } from './abortError';\nimport { sleep } from './sleep';\n\nexport type RetryOptions = {\n delay?: number | ((attempt: number) => number);\n onError?: (error: unknown) => void;\n shouldRetry?: (error: unknown, attempt: number) => boolean;\n signal?: AbortSignal;\n timeout?: number;\n times?: number;\n};\n\nfunction buildSignal(timeout: number | undefined, signal: AbortSignal | undefined): AbortSignal | undefined {\n const parts = [timeout !== undefined ? AbortSignal.timeout(timeout) : undefined, signal].filter(\n (s): s is AbortSignal => s != null,\n );\n\n if (parts.length === 0) return undefined;\n\n if (parts.length === 1) return parts[0];\n\n return AbortSignal.any(parts);\n}\n\n/**\n * Retries an async function with optional per-attempt timeout, delay strategy, and abort support.\n * The function receives a merged AbortSignal from the per-attempt timeout and any external signal.\n * On total failure, throws the last error (use `attempt()` to get an `AttemptResult` without throwing).\n *\n * @example\n * ```ts\n * // Basic retry\n * const data = await retry(() => fetch('/api').then(r => r.json()), { times: 3 });\n *\n * // With per-attempt timeout and cancellation\n * const data = await retry(\n * async (signal) => fetch('/api', { signal }).then(r => r.json()),\n * { times: 3, timeout: 5000 },\n * );\n *\n * // As AttemptResult (never throws) — combine with attempt()\n * const result = await attempt(() => retry(fn, { times: 3 }));\n * ```\n *\n * @param fn - Async function to retry. Receives a merged AbortSignal when timeout or signal is set.\n * @param options - Retry configuration.\n * @param [options.times=3] - Total attempts including the first.\n * @param [options.delay=250] - Delay between retries in ms, or a function of (attemptIndex).\n * @param [options.timeout] - Per-attempt timeout in milliseconds.\n * @param [options.signal] - External AbortSignal to cancel all retries.\n * @param [options.shouldRetry] - Predicate called after each non-final failure.\n * Receives the error and the number of failures so far (0-indexed: `0` on the first failure,\n * `1` on the second, etc.). Return `false` to abort immediately. **Not called on the final attempt**\n * (use `onError` to observe the final error unconditionally).\n * @param [options.onError] - Called with the last error before rethrowing — both on final attempt exhaustion\n * and when `shouldRetry` returns `false` to abort early.\n * @returns The resolved value.\n * @throws {ArsenalValidationError} If `times` is not a positive integer.\n * @throws The last error if all attempts fail.\n */\nexport async function retry<T>(\n fn: (signal?: AbortSignal) => Promise<T>,\n { delay = 250, onError, shouldRetry, signal, timeout, times = 3 }: RetryOptions = {},\n): Promise<T> {\n if (!Number.isInteger(times) || times < 1) {\n throw new ArsenalValidationError(`retry: times must be a positive integer, got ${times}`);\n }\n\n for (let tryCount = 1; tryCount <= times; tryCount++) {\n if (signal?.aborted) throw abortError(signal);\n\n const callSignal = buildSignal(timeout, signal);\n\n try {\n return await fn(callSignal);\n } catch (err) {\n if (tryCount === times) {\n onError?.(err);\n throw err;\n }\n\n if (shouldRetry && !shouldRetry(err, tryCount - 1)) {\n onError?.(err);\n throw err;\n }\n\n const ms = typeof delay === 'function' ? delay(tryCount - 1) : delay;\n\n if (ms > 0) await sleep(ms, signal);\n }\n }\n\n /* unreachable — the loop always returns or throws before exhausting all attempts */\n return undefined as never;\n}\n"],"mappings":";;;;AAaA,SAAS,EAAY,GAA6B,GAA0D;CAC1G,IAAM,IAAQ,CAAC,MAAY,KAAA,IAA2C,KAAA,IAA/B,YAAY,QAAQ,CAAO,GAAe,CAAM,CAAC,CAAC,QACtF,MAAwB,KAAK,IAChC;CAEI,MAAM,WAAW,GAIrB,OAFI,EAAM,WAAW,IAAU,EAAM,KAE9B,YAAY,IAAI,CAAK;AAC9B;AAsCA,eAAsB,EACpB,GACA,EAAE,WAAQ,KAAK,YAAS,gBAAa,WAAQ,YAAS,WAAQ,MAAoB,CAAC,GACvE;CACZ,IAAI,CAAC,OAAO,UAAU,CAAK,KAAK,IAAQ,GACtC,MAAM,IAAI,EAAuB,gDAAgD,GAAO;CAG1F,KAAK,IAAI,IAAW,GAAG,KAAY,GAAO,KAAY;EACpD,IAAI,GAAQ,SAAS,MAAM,EAAW,CAAM;EAE5C,IAAM,IAAa,EAAY,GAAS,CAAM;EAE9C,IAAI;GACF,OAAO,MAAM,EAAG,CAAU;EAC5B,SAAS,GAAK;GAMZ,IALI,MAAa,KAKb,KAAe,CAAC,EAAY,GAAK,IAAW,CAAC,GAE/C,MADA,IAAU,CAAG,GACP;GAGR,IAAM,IAAK,OAAO,KAAU,aAAa,EAAM,IAAW,CAAC,IAAI;GAE/D,AAAI,IAAK,KAAG,MAAM,EAAM,GAAI,CAAM;EACpC;CACF;AAIF"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("./abortError.cjs");async function t(t,n){return n?n.aborted?Promise.reject(e.abortError(n)):new Promise((r,i)=>{let a=setTimeout(()=>{n.removeEventListener(`abort`,o),r()},t),o=()=>{clearTimeout(a),n.removeEventListener(`abort`,o),i(e.abortError(n))};n.addEventListener(`abort`,o)}):new Promise(e=>setTimeout(e,t))}exports.sleep=t;
|
|
2
|
+
//# sourceMappingURL=sleep.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sleep.cjs","names":[],"sources":["../../src/async/sleep.ts"],"sourcesContent":["import { abortError } from './abortError';\n\n/**\n * Creates a Promise that resolves after a specified amount of time.\n * If an `AbortSignal` is provided and fires before the delay elapses, the promise rejects with\n * the signal's reason (or a generic `DOMException('Aborted', 'AbortError')`).\n *\n * @example\n * ```ts\n * sleep(1000).then(() => console.log('Hello, world!')); // logs after 1 second\n *\n * // With abort support\n * const controller = new AbortController();\n * await sleep(5000, controller.signal); // rejects immediately when aborted\n * ```\n *\n * @param timeout - The number of milliseconds to wait before resolving the Promise.\n * @param signal - Optional AbortSignal to cancel the sleep early.\n *\n * @returns A Promise that resolves after the specified time.\n */\nexport async function sleep(timeout: number, signal?: AbortSignal): Promise<void> {\n if (!signal) {\n return new Promise((resolve) => setTimeout(resolve, timeout));\n }\n\n if (signal.aborted) {\n return Promise.reject(abortError(signal));\n }\n\n return new Promise<void>((resolve, reject) => {\n const id = setTimeout(() => {\n signal.removeEventListener('abort', onAbort);\n resolve();\n }, timeout);\n\n const onAbort = () => {\n clearTimeout(id);\n signal.removeEventListener('abort', onAbort);\n reject(abortError(signal));\n };\n\n signal.addEventListener('abort', onAbort);\n });\n}\n"],"mappings":"oCAqBA,eAAsB,EAAM,EAAiB,EAAqC,CAShF,OARK,EAID,EAAO,QACF,QAAQ,OAAO,EAAA,WAAW,CAAM,CAAC,EAGnC,IAAI,SAAe,EAAS,IAAW,CAC5C,IAAM,EAAK,eAAiB,CAC1B,EAAO,oBAAoB,QAAS,CAAO,EAC3C,EAAQ,CACV,EAAG,CAAO,EAEJ,MAAgB,CACpB,aAAa,CAAE,EACf,EAAO,oBAAoB,QAAS,CAAO,EAC3C,EAAO,EAAA,WAAW,CAAM,CAAC,CAC3B,EAEA,EAAO,iBAAiB,QAAS,CAAO,CAC1C,CAAC,EApBQ,IAAI,QAAS,GAAY,WAAW,EAAS,CAAO,CAAC,CAqBhE"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a Promise that resolves after a specified amount of time.
|
|
3
|
+
* If an `AbortSignal` is provided and fires before the delay elapses, the promise rejects with
|
|
4
|
+
* the signal's reason (or a generic `DOMException('Aborted', 'AbortError')`).
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* sleep(1000).then(() => console.log('Hello, world!')); // logs after 1 second
|
|
9
|
+
*
|
|
10
|
+
* // With abort support
|
|
11
|
+
* const controller = new AbortController();
|
|
12
|
+
* await sleep(5000, controller.signal); // rejects immediately when aborted
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @param timeout - The number of milliseconds to wait before resolving the Promise.
|
|
16
|
+
* @param signal - Optional AbortSignal to cancel the sleep early.
|
|
17
|
+
*
|
|
18
|
+
* @returns A Promise that resolves after the specified time.
|
|
19
|
+
*/
|
|
20
|
+
export declare function sleep(timeout: number, signal?: AbortSignal): Promise<void>;
|
|
21
|
+
//# sourceMappingURL=sleep.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sleep.d.ts","sourceRoot":"","sources":["../../src/async/sleep.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAuBhF"}
|