Georgy Shive e61781c750 Реализовал класс Mutex для синхронизации асинхронных элементов,
синхронизовал подгрузку оборудования в менеджере оборудования со
списком в котором они отображаются.
2025-02-11 17:06:48 +07:00

28 lines
645 B
TypeScript

import { _decorator } from 'cc';
const { ccclass } = _decorator;
@ccclass('Mutex')
export class Mutex {
private queue: Array<(value: void) => void> = [];
private locked = false;
async acquire(): Promise<void> {
if (!this.locked) {
this.locked = true;
return;
}
return new Promise(resolve => this.queue.push(resolve));
}
release(): void {
if (this.queue.length > 0) {
const nextResolver = this.queue.shift();
if (nextResolver) {
nextResolver();
}
} else {
this.locked = false;
}
}
}