Skip to content

Commit 1c14764

Browse files
scheiboZarel
authored andcommitted
Make sure BattleStream only calls _destroy once (#5382)
1 parent 19bde75 commit 1c14764

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

sim/battle-stream.ts

+4-10
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ function splitFirst(str: string, delimiter: string, limit: number = 1) {
3939
}
4040

4141
export class BattleStream extends Streams.ObjectReadWriteStream<string> {
42-
readonly debug: boolean;
43-
readonly keepAlive: boolean;
42+
debug: boolean;
43+
keepAlive: boolean;
4444
battle: Battle | null;
4545

4646
constructor(options: {debug?: boolean, keepAlive?: boolean} = {}) {
@@ -92,10 +92,7 @@ export class BattleStream extends Streams.ObjectReadWriteStream<string> {
9292
options.send = (t: string, data: any) => {
9393
if (Array.isArray(data)) data = data.join("\n");
9494
this.push(`${t}\n${data}`);
95-
if (t === 'end' && !this.keepAlive) {
96-
this.push(null);
97-
this._destroy();
98-
}
95+
if (t === 'end' && !this.keepAlive) this.push(null);
9996
};
10097
if (this.debug) options.debug = true;
10198
this.battle = new Battle(options);
@@ -164,10 +161,7 @@ export class BattleStream extends Streams.ObjectReadWriteStream<string> {
164161
this._destroy();
165162
}
166163
_destroy() {
167-
if (this.battle) {
168-
this.battle.destroy();
169-
}
170-
this.battle = null;
164+
if (this.battle) this.battle.destroy();
171165
}
172166
}
173167

0 commit comments

Comments
 (0)