diff options
author | Joffrey Bion <joffrey.bion@booking.com> | 2020-09-14 00:50:29 +0200 |
---|---|---|
committer | Joffrey Bion <joffrey.bion@booking.com> | 2020-09-14 00:50:29 +0200 |
commit | 735cbbdf98befb25cef38c2b2abe6c70d6414b13 (patch) | |
tree | 5a41f385c84cd1e45024f13a9004606eb17f02ec /sw-client/src/commonMain/kotlin/org/luxons | |
parent | Simplify local run docker command (with DockerHub) (diff) | |
download | seven-wonders-735cbbdf98befb25cef38c2b2abe6c70d6414b13.tar.gz seven-wonders-735cbbdf98befb25cef38c2b2abe6c70d6414b13.tar.bz2 seven-wonders-735cbbdf98befb25cef38c2b2abe6c70d6414b13.zip |
Upgrade to Krossbow 0.41.0
Diffstat (limited to 'sw-client/src/commonMain/kotlin/org/luxons')
-rw-r--r-- | sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt b/sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt index 05c6bf94..9a9fe356 100644 --- a/sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt +++ b/sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt @@ -1,10 +1,6 @@ package org.luxons.sevenwonders.client -import kotlinx.coroutines.CoroutineStart import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.coroutines.async -import kotlinx.coroutines.coroutineScope -import kotlinx.coroutines.delay import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.first import kotlinx.serialization.DeserializationStrategy @@ -61,20 +57,17 @@ private suspend inline fun <reified T : Any, reified U : Any> StompSessionWithKx payload: T? = null, serializer: SerializationStrategy<T>, deserializer: DeserializationStrategy<U>, -): U = coroutineScope { - val sub = async(start = CoroutineStart.UNDISPATCHED) { - subscribe(receiveDestination, deserializer).first() - } - delay(30) // ensures the subscription happened +): U { + val sub = subscribe(receiveDestination, deserializer) convertAndSend(sendDestination, payload, serializer) - sub.await() + return sub.first() } class SevenWondersSession(private val stompSession: StompSessionWithKxSerialization) { suspend fun disconnect() = stompSession.disconnect() - fun watchErrors(): Flow<ErrorDTO> = stompSession.subscribe("/user/queue/errors", ErrorDTO.serializer()) + suspend fun watchErrors(): Flow<ErrorDTO> = stompSession.subscribe("/user/queue/errors", ErrorDTO.serializer()) suspend fun chooseName(displayName: String, icon: Icon? = null): ConnectedPlayer = stompSession.request( sendDestination = "/app/chooseName", @@ -84,7 +77,7 @@ class SevenWondersSession(private val stompSession: StompSessionWithKxSerializat deserializer = ConnectedPlayer.serializer(), ) - fun watchGames(): Flow<List<LobbyDTO>> = + suspend fun watchGames(): Flow<List<LobbyDTO>> = stompSession.subscribe("/topic/games", ListSerializer(LobbyDTO.serializer())) suspend fun createGame(gameName: String): LobbyDTO = stompSession.request( @@ -135,7 +128,8 @@ class SevenWondersSession(private val stompSession: StompSessionWithKxSerializat ) } - fun watchLobbyUpdates(): Flow<LobbyDTO> = stompSession.subscribe("/user/queue/lobby/updated", LobbyDTO.serializer()) + suspend fun watchLobbyUpdates(): Flow<LobbyDTO> = + stompSession.subscribe("/user/queue/lobby/updated", LobbyDTO.serializer()) suspend fun awaitGameStart(gameId: Long): PlayerTurnInfo { val startEvents = stompSession.subscribe("/user/queue/lobby/$gameId/started", PlayerTurnInfo.serializer()) @@ -146,20 +140,20 @@ class SevenWondersSession(private val stompSession: StompSessionWithKxSerializat stompSession.sendEmptyMsg("/app/lobby/startGame") } - fun watchPlayerReady(gameId: Long): Flow<String> = + suspend fun watchPlayerReady(gameId: Long): Flow<String> = stompSession.subscribe("/topic/game/$gameId/playerReady", String.serializer()) - fun watchPreparedCards(gameId: Long): Flow<PreparedCard> = + suspend fun watchPreparedCards(gameId: Long): Flow<PreparedCard> = stompSession.subscribe("/topic/game/$gameId/prepared", PreparedCard.serializer()) - fun watchTurns(): Flow<PlayerTurnInfo> = + suspend fun watchTurns(): Flow<PlayerTurnInfo> = stompSession.subscribe("/user/queue/game/turn", PlayerTurnInfo.serializer()) suspend fun sayReady() { stompSession.sendEmptyMsg("/app/game/sayReady") } - fun watchOwnMoves(): Flow<PlayerMove> = + suspend fun watchOwnMoves(): Flow<PlayerMove> = stompSession.subscribe("/user/queue/game/preparedMove", PlayerMove.serializer()) suspend fun prepareMove(move: PlayerMove) { |