From 0a7c60e8b7ae44b52afaea45e650ff41081ada11 Mon Sep 17 00:00:00 2001 From: cha0s Date: Tue, 8 Oct 2019 03:23:58 -0500 Subject: [PATCH] refactor: destroy async to avoid issues within tick --- packages/entity/traits/existent.trait.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/entity/traits/existent.trait.js b/packages/entity/traits/existent.trait.js index 94c792f..dea0ce2 100644 --- a/packages/entity/traits/existent.trait.js +++ b/packages/entity/traits/existent.trait.js @@ -36,8 +36,10 @@ export class Existent extends decorate(Trait) { } this._isDestroying = true; this.entity.isTicking = false; - this.entity.emit('destroy'); - this.entity.emit('destroyed'); + return Promise.resolve().then(() => { + this.entity.emit('destroy'); + this.entity.emit('destroyed'); + }); }, destroyGently: () => {