@salesforce/lds-utils-adapters 1.100.3 → 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.
- package/dist/AsyncWorkerPool.d.ts +9 -0
- package/dist/ldsAdapterUtils.js +33 -1
- package/dist/main.d.ts +1 -0
- package/package.json +1 -1
package/dist/ldsAdapterUtils.js
CHANGED
|
@@ -303,4 +303,36 @@ function runAdapterWithReport(adapterName, adapter, adapterConfig, requestContex
|
|
|
303
303
|
}
|
|
304
304
|
}
|
|
305
305
|
|
|
306
|
-
|
|
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