private async Task NonReentrantRegisterPlayer(IPlayerGrain player, PlayerInfo playerInfo) { this.playersInLobby.Add(new Tuple <IPlayerGrain, PlayerInfo>(player, playerInfo)); if (this.playersInLobby.Count == MAX_PLAYERS) { var gameServer = GameServerGrainFactory.GetGrain(Guid.NewGuid()); await gameServer.StartGame(this.playersInLobby.Select(_ => _.Item1).ToList()); this.playersInLobby.Clear(); } }
async Task ILobbyGrain.RegisterPlayer(IPlayerGrain player, PlayerInfo playerInfo) { List <Tuple <IPlayerGrain, PlayerInfo> > playerSet = null; var newPlayer = new Tuple <IPlayerGrain, PlayerInfo>(player, playerInfo); lock (_lock) // do the collection mgmt operations in a locked section, do awaiting the game server spawn outside { this.playersInLobby.Add(newPlayer); if (this.playersInLobby.Count == MAX_PLAYERS) { playerSet = this.playersInLobby; this.playersInLobby = new List <Tuple <IPlayerGrain, PlayerInfo> >(); } } if (playerSet != null) { var gameServer = GameServerGrainFactory.GetGrain(Guid.NewGuid()); await gameServer.StartGame(playerSet.Select(_ => _.Item1).ToList()); } }