Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure BattleStream only calls _destroy once #5382

Merged
merged 1 commit into from
Mar 30, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions sim/battle-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ function splitFirst(str: string, delimiter: string, limit: number = 1) {
}

export class BattleStream extends Streams.ObjectReadWriteStream<string> {
readonly debug: boolean;
readonly keepAlive: boolean;
debug: boolean;
keepAlive: boolean;
battle: Battle | null;

constructor(options: {debug?: boolean, keepAlive?: boolean} = {}) {
Expand Down Expand Up @@ -92,10 +92,7 @@ export class BattleStream extends Streams.ObjectReadWriteStream<string> {
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);
Expand Down Expand Up @@ -164,10 +161,7 @@ export class BattleStream extends Streams.ObjectReadWriteStream<string> {
this._destroy();
}
_destroy() {
if (this.battle) {
this.battle.destroy();
}
this.battle = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't this line also removed? Am I thinking of a different stream or did this never get merged or what?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're thinking of c45ff0e on #5370 which has not been merged into HEAD yet. I just redid those changes on this PR because its not like they were specific to #5370, they just were discovered there, and landing them earlier seems useful given all my PRs involving the harness seem to get bogged down :)

if (this.battle) this.battle.destroy();
}
}

Expand Down