chore: destroy async

This commit is contained in:
cha0s 2021-07-08 05:44:48 -05:00
parent 901b36e5c7
commit a94ca185dc

View File

@ -57,10 +57,17 @@ export default (latus) => {
this.startSynchronizing(entity);
}
destroy() {
async destroy() {
await this.destroyEntities();
}
destroyEntities() {
const promises = [];
for (let i = 0; i < this.#flatEntities.length; i++) {
this.#flatEntities[i].destroy();
promises.push(this.#flatEntities[i].destroy());
this.#flatEntities[i].tick(Infinity);
}
return Promise.all(promises);
}
get entities() {
@ -78,6 +85,7 @@ export default (latus) => {
if (0 === json.length) {
return;
}
await this.destroyEntities();
const {Entity} = latus.get('%resources');
const entityInstances = await Promise.all(json.map((entity) => Entity.load(entity)));
for (let i = 0; i < entityInstances.length; i++) {