feat: v2.12.0 - UI/UX Refinement (Model Sync & Premium Tooltips)
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import { logInfo } from '../utils';
|
||||
|
||||
/**
|
||||
* AsyncLockManager: Prevents race conditions by ensuring only one task
|
||||
* can access a specific resource (e.g., a file path) at a time.
|
||||
*/
|
||||
export class AsyncLockManager {
|
||||
private locks: Map<string, Promise<void>> = new Map();
|
||||
|
||||
/**
|
||||
* Acquires a lock for a specific resource.
|
||||
* If the resource is already locked, it waits until the previous task finishes.
|
||||
*/
|
||||
public async acquire(resourceId: string): Promise<() => void> {
|
||||
const previousLock = this.locks.get(resourceId) || Promise.resolve();
|
||||
|
||||
let release: () => void;
|
||||
const newLock = new Promise<void>((resolve) => {
|
||||
release = resolve;
|
||||
});
|
||||
|
||||
this.locks.set(resourceId, previousLock.then(() => newLock));
|
||||
|
||||
await previousLock;
|
||||
logInfo(`Lock acquired for: ${resourceId}`);
|
||||
|
||||
return () => {
|
||||
logInfo(`Lock released for: ${resourceId}`);
|
||||
release();
|
||||
if (this.locks.get(resourceId) === newLock) {
|
||||
this.locks.delete(resourceId);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Export as a singleton for the entire agent process
|
||||
export const lockManager = new AsyncLockManager();
|
||||
Reference in New Issue
Block a user