@salesforce/lds-utils-adapters 1.100.2 → 1.100.4

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,9 @@
1
+ export declare class AsyncWorkerPool {
2
+ private concurrency;
3
+ private queue;
4
+ private activeWorkers;
5
+ constructor(concurrency: number);
6
+ push<T>(workFn: () => Promise<T>): Promise<T>;
7
+ cancel(): void;
8
+ private work;
9
+ }
@@ -303,4 +303,36 @@ function runAdapterWithReport(adapterName, adapter, adapterConfig, requestContex
303
303
  }
304
304
  }
305
305
 
306
- export { runAdapterWithReport };
306
+ class AsyncWorkerPool {
307
+ constructor(concurrency) {
308
+ this.queue = [];
309
+ this.activeWorkers = 0;
310
+ this.concurrency = concurrency;
311
+ }
312
+ push(workFn) {
313
+ return new Promise((resolve, reject) => {
314
+ this.queue.push(async () => {
315
+ return workFn().then(resolve).catch(reject);
316
+ });
317
+ this.work();
318
+ });
319
+ }
320
+ cancel() {
321
+ this.queue = [];
322
+ // TODO [W-12513105]: thread cancellation through to active workers
323
+ }
324
+ work() {
325
+ while (this.queue.length > 0 && this.activeWorkers < this.concurrency) {
326
+ this.activeWorkers += 1;
327
+ const next = this.queue.shift();
328
+ if (next) {
329
+ next().finally(() => {
330
+ this.activeWorkers -= 1;
331
+ this.work();
332
+ });
333
+ }
334
+ }
335
+ }
336
+ }
337
+
338
+ export { AsyncWorkerPool, runAdapterWithReport };
package/dist/main.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export { runAdapterWithReport } from './runAdapterWithReport';
2
2
  export { AdapterReport } from './AdapterReport';
3
+ export { AsyncWorkerPool } from './AsyncWorkerPool';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/lds-utils-adapters",
3
- "version": "1.100.2",
3
+ "version": "1.100.4",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "description": "LDS Adapter Utilities",
6
6
  "main": "dist/ldsAdapterUtils.js",