Fix matchFinished event occuring after final playerFinished event.

parent 271be4df
......@@ -306,19 +306,29 @@ class BanchoLobby extends EventEmitter {
this.emit("playerFinished", player.score);
}, (err) => this.banchojs.emit("error", err));
break;
case "matchFinished":
case "matchAborted":
/**
* @event BanchoLobby#matchFinished
* @type {Array.<BanchoLobbyPlayerScore>} Sorted scores array
* @event BanchoLobby#matchAborted
*/
this.playing = false;
this.emit("matchAborted");
break;
case "matchFinished":
/**
* @event BanchoLobby#matchAborted
* @event BanchoLobby#matchFinished
* @type {Array.<BanchoLobbyPlayerScore>} Sorted scores array
*/
this.playing = false;
this.sortScores();
this.emit(regex.name, this.scores);
// Due to players resolving, matchFinished may be emitted and scores sorted before every playerFinished are done being processed.
// For some reason, even though a Promise may not have anything async, the "then" functions may still be executed asynchronously...
// However, they seem to be executed in order for some reason. So a workaround for this is to wait for the callback of a resolved Promise to be called.
Promise.resolve().then(() => {
// This ensures sorting/emitting is executed after all names are resolved.
this.pushPlayerCreationQueue(() => {
this.sortScores();
this.emit(regex.name, this.scores);
this.playersCreationCallback();
});
});
break;
case "invalidBeatmapId":
case "passwordRemoved":
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment