@cloudflare/workers-response-store 0.1.0-beta.0 → 0.1.0-beta.2

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.
@@ -0,0 +1,3 @@
1
+ //#region src/r2-concurrency.d.ts
2
+ export declare function mapSettledWithR2Concurrency<T, R>(values: readonly T[], callback: (value: T) => Promise<R>): Promise<PromiseSettledResult<R>[]>;
3
+ //#endregion
@@ -0,0 +1,25 @@
1
+ //#region src/r2-concurrency.ts
2
+ const MAX_R2_CONCURRENCY = 6;
3
+ async function mapSettledWithR2Concurrency(values, callback) {
4
+ const results = [];
5
+ let nextIndex = 0;
6
+ await Promise.all(Array.from({ length: Math.min(MAX_R2_CONCURRENCY, values.length) }, async () => {
7
+ while (nextIndex < values.length) {
8
+ const index = nextIndex++;
9
+ try {
10
+ results[index] = {
11
+ status: "fulfilled",
12
+ value: await callback(values[index])
13
+ };
14
+ } catch (reason) {
15
+ results[index] = {
16
+ status: "rejected",
17
+ reason
18
+ };
19
+ }
20
+ }
21
+ }));
22
+ return results;
23
+ }
24
+ //#endregion
25
+ export { mapSettledWithR2Concurrency };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudflare/workers-response-store",
3
- "version": "0.1.0-beta.0",
3
+ "version": "0.1.0-beta.2",
4
4
  "description": "An R2-backed programmatic response store for Cloudflare Workers.",
5
5
  "homepage": "https://vinext.dev/",
6
6
  "license": "MIT",