feat: v2.12.0 - UI/UX Refinement (Model Sync & Premium Tooltips)
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import { logInfo, logError } from '../utils';
|
||||
|
||||
/**
|
||||
* ActionQueueManager: Manages large-scale tasks by processing them
|
||||
* sequentially to prevent resource exhaustion and I/O bottlenecks.
|
||||
*/
|
||||
export class ActionQueueManager {
|
||||
private queue: (() => Promise<void>)[] = [];
|
||||
private isProcessing: boolean = false;
|
||||
|
||||
/**
|
||||
* Adds a task to the queue.
|
||||
*/
|
||||
public async enqueue<T>(task: () => Promise<T>): Promise<T> {
|
||||
return new Promise<T>((resolve, reject) => {
|
||||
this.queue.push(async () => {
|
||||
try {
|
||||
const result = await task();
|
||||
resolve(result);
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
this.processNext();
|
||||
});
|
||||
}
|
||||
|
||||
private async processNext() {
|
||||
if (this.isProcessing || this.queue.length === 0) return;
|
||||
|
||||
this.isProcessing = true;
|
||||
const task = this.queue.shift();
|
||||
|
||||
if (task) {
|
||||
try {
|
||||
// Add a micro-delay to allow system breathing room between heavy I/O
|
||||
await new Promise(r => setTimeout(r, 50));
|
||||
await task();
|
||||
} catch (error) {
|
||||
logError('Task in queue failed:', error);
|
||||
} finally {
|
||||
this.isProcessing = false;
|
||||
this.processNext();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public getPendingCount(): number {
|
||||
return this.queue.length;
|
||||
}
|
||||
}
|
||||
|
||||
export const actionQueue = new ActionQueueManager();
|
||||
Reference in New Issue
Block a user