diff options
author | joffrey-bion <joffrey.bion@gmail.com> | 2021-02-13 16:46:02 +0100 |
---|---|---|
committer | joffrey-bion <joffrey.bion@gmail.com> | 2021-02-13 16:46:02 +0100 |
commit | 6842a503099a42c88c98df60c3e4db9529e9e624 (patch) | |
tree | 870e5b43c0c2071a17231f1dbe118c213fec16d1 /sw-client | |
parent | Rename some client functions (diff) | |
download | seven-wonders-6842a503099a42c88c98df60c3e4db9529e9e624.tar.gz seven-wonders-6842a503099a42c88c98df60c3e4db9529e9e624.tar.bz2 seven-wonders-6842a503099a42c88c98df60c3e4db9529e9e624.zip |
Fix potential race in chooseName
Diffstat (limited to 'sw-client')
-rw-r--r-- | sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt | 23 |
1 files changed, 14 insertions, 9 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 3a3cb989..50b9b70c 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 @@ -42,16 +42,21 @@ class SevenWondersSession(private val stompSession: StompSessionWithKxSerializat suspend fun watchErrors(): Flow<ErrorDTO> = stompSession.subscribe("/user/queue/errors", ErrorDTO.serializer()) suspend fun chooseName(displayName: String, icon: Icon? = null, isHuman: Boolean = true): ConnectedPlayer { - val sub = stompSession.subscribe( - destination = "/user/queue/nameChoice", - deserializer = ConnectedPlayer.serializer(), + return doAndWaitForEvent( + send = { + stompSession.convertAndSend( + destination = "/app/chooseName", + body = ChooseNameAction(displayName, icon, isHuman), + serializer = ChooseNameAction.serializer(), + ) + }, + subscribe = { + stompSession.subscribe( + destination = "/user/queue/nameChoice", + deserializer = ConnectedPlayer.serializer(), + ) + } ) - stompSession.convertAndSend( - destination = "/app/chooseName", - body = ChooseNameAction(displayName, icon, isHuman), - serializer = ChooseNameAction.serializer(), - ) - return sub.first() } suspend fun watchGames(): Flow<GameListEvent> = |