From 71f2fc4f25bdfdeac7db9b8e62144c3110e3bf6a Mon Sep 17 00:00:00 2001 From: joffrey-bion Date: Sat, 12 Dec 2020 16:18:28 +0100 Subject: Fix race conditions for game start and tests Resolves: https://github.com/joffrey-bion/seven-wonders/issues/70 --- .../main/kotlin/org/luxons/sevenwonders/bot/SevenWondersBot.kt | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'sw-bot') diff --git a/sw-bot/src/main/kotlin/org/luxons/sevenwonders/bot/SevenWondersBot.kt b/sw-bot/src/main/kotlin/org/luxons/sevenwonders/bot/SevenWondersBot.kt index 87ba7983..6170acb8 100644 --- a/sw-bot/src/main/kotlin/org/luxons/sevenwonders/bot/SevenWondersBot.kt +++ b/sw-bot/src/main/kotlin/org/luxons/sevenwonders/bot/SevenWondersBot.kt @@ -2,10 +2,7 @@ package org.luxons.sevenwonders.bot import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.delay -import kotlinx.coroutines.flow.collect -import kotlinx.coroutines.flow.onCompletion -import kotlinx.coroutines.flow.onStart -import kotlinx.coroutines.flow.takeWhile +import kotlinx.coroutines.flow.* import kotlinx.coroutines.withTimeout import org.luxons.sevenwonders.client.SevenWondersClient import org.luxons.sevenwonders.client.SevenWondersSession @@ -38,8 +35,9 @@ class SevenWondersBot( suspend fun play(serverUrl: String, gameId: Long) = withTimeout(botConfig.globalTimeout) { val session = client.connect(serverUrl) session.chooseName(displayName, Icon("desktop")) + val gameStartedEvents = session.watchGameStarted() session.joinGameAndWaitLobby(gameId) - val firstTurn = session.awaitGameStart(gameId) + val firstTurn = gameStartedEvents.first() session.watchTurns() .onStart { emit(firstTurn) } -- cgit