@zelgadis87/utils-core 5.4.6 → 5.4.7
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/.rollup/index.cjs +21 -3
- package/.rollup/index.cjs.map +1 -1
- package/.rollup/index.d.ts +8 -0
- package/.rollup/index.mjs +21 -3
- package/.rollup/index.mjs.map +1 -1
- package/.rollup/tsconfig.tsbuildinfo +1 -1
- package/CHANGELOG.md +6 -0
- package/package.json +1 -1
- package/src/async/Semaphore.ts +25 -3
package/.rollup/index.d.ts
CHANGED
|
@@ -1369,7 +1369,15 @@ declare class Semaphore {
|
|
|
1369
1369
|
constructor(availableSlots: number);
|
|
1370
1370
|
private _awaitSlot;
|
|
1371
1371
|
private _releaseSlot;
|
|
1372
|
+
submit<T>(fn: TAsyncProducer<T> | TProducer<T>, cooldown?: TimeDuration): Promise<T>;
|
|
1373
|
+
/** @deprecated[2026.04.01]: Use {@link submit} instead. */
|
|
1372
1374
|
execute<T>(fn: TAsyncProducer<T> | TProducer<T>, cooldown?: TimeDuration): Promise<T>;
|
|
1375
|
+
/** Called when a task is added to the queue or immediately starts. Override in subclasses. */
|
|
1376
|
+
protected onTaskAdded(): void;
|
|
1377
|
+
/** Called when a task starts executing (acquires a slot). Override in subclasses. */
|
|
1378
|
+
protected onTaskStarted(): void;
|
|
1379
|
+
/** Called when a task completes and releases its slot. Override in subclasses. */
|
|
1380
|
+
protected onTaskCompleted(): void;
|
|
1373
1381
|
get availableSlots(): number;
|
|
1374
1382
|
get queueSize(): number;
|
|
1375
1383
|
get inProgressSize(): number;
|
package/.rollup/index.mjs
CHANGED
|
@@ -151,9 +151,27 @@ class Semaphore {
|
|
|
151
151
|
this._inProgress -= 1;
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
|
-
async
|
|
155
|
-
|
|
156
|
-
|
|
154
|
+
async submit(fn, cooldown = TimeDuration.ZERO) {
|
|
155
|
+
this.onTaskAdded();
|
|
156
|
+
await this._awaitSlot();
|
|
157
|
+
this.onTaskStarted();
|
|
158
|
+
const [result, error] = await withTryCatchAsync(async () => fn());
|
|
159
|
+
this.onTaskCompleted();
|
|
160
|
+
void cooldown.delay(() => this._releaseSlot());
|
|
161
|
+
if (error)
|
|
162
|
+
throw error;
|
|
163
|
+
return result;
|
|
164
|
+
}
|
|
165
|
+
/** @deprecated[2026.04.01]: Use {@link submit} instead. */
|
|
166
|
+
execute(fn, cooldown = TimeDuration.ZERO) {
|
|
167
|
+
return this.submit(fn, cooldown);
|
|
168
|
+
}
|
|
169
|
+
/** Called when a task is added to the queue or immediately starts. Override in subclasses. */
|
|
170
|
+
onTaskAdded() { }
|
|
171
|
+
/** Called when a task starts executing (acquires a slot). Override in subclasses. */
|
|
172
|
+
onTaskStarted() { }
|
|
173
|
+
/** Called when a task completes and releases its slot. Override in subclasses. */
|
|
174
|
+
onTaskCompleted() { }
|
|
157
175
|
get availableSlots() {
|
|
158
176
|
return this._availableSlots;
|
|
159
177
|
}
|