синхронизовал подгрузку оборудования в менеджере оборудования со списком в котором они отображаются.
28 lines
645 B
TypeScript
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;
|
|
}
|
|
}
|
|
}
|