summaryrefslogtreecommitdiff
path: root/sw-client
diff options
context:
space:
mode:
authorjoffrey-bion <joffrey.bion@gmail.com>2021-02-13 16:46:02 +0100
committerjoffrey-bion <joffrey.bion@gmail.com>2021-02-13 16:46:02 +0100
commit6842a503099a42c88c98df60c3e4db9529e9e624 (patch)
tree870e5b43c0c2071a17231f1dbe118c213fec16d1 /sw-client
parentRename some client functions (diff)
downloadseven-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.kt23
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> =
bgstack15