From 43c6bbd931cf9b7d0d98f248354fd57d73036543 Mon Sep 17 00:00:00 2001 From: Kirk Scheibelhut Date: Sat, 30 Mar 2019 07:18:51 -0700 Subject: [PATCH] Make sure BattleStream only calls _destroy once --- sim/battle-stream.ts | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/sim/battle-stream.ts b/sim/battle-stream.ts index d75b21f66836f..79a1b3021f08a 100644 --- a/sim/battle-stream.ts +++ b/sim/battle-stream.ts @@ -39,8 +39,8 @@ function splitFirst(str: string, delimiter: string, limit: number = 1) { } export class BattleStream extends Streams.ObjectReadWriteStream { - readonly debug: boolean; - readonly keepAlive: boolean; + debug: boolean; + keepAlive: boolean; battle: Battle | null; constructor(options: {debug?: boolean, keepAlive?: boolean} = {}) { @@ -92,10 +92,7 @@ export class BattleStream extends Streams.ObjectReadWriteStream { options.send = (t: string, data: any) => { if (Array.isArray(data)) data = data.join("\n"); this.push(`${t}\n${data}`); - if (t === 'end' && !this.keepAlive) { - this.push(null); - this._destroy(); - } + if (t === 'end' && !this.keepAlive) this.push(null); }; if (this.debug) options.debug = true; this.battle = new Battle(options); @@ -164,10 +161,7 @@ export class BattleStream extends Streams.ObjectReadWriteStream { this._destroy(); } _destroy() { - if (this.battle) { - this.battle.destroy(); - } - this.battle = null; + if (this.battle) this.battle.destroy(); } }