summaryrefslogtreecommitdiff
path: root/sw-client/src/commonMain/kotlin/org
diff options
context:
space:
mode:
authorJoffrey Bion <joffrey.bion@booking.com>2020-05-17 18:22:23 +0200
committerJoffrey Bion <joffrey.bion@booking.com>2020-05-21 11:31:36 +0200
commitc4d9e5e9467130de09b7810097c0b3779219ffe0 (patch)
tree1bf7f326745672e3e0ba749bee21d420eea84f38 /sw-client/src/commonMain/kotlin/org
parentFix background->backgrounds path (diff)
downloadseven-wonders-c4d9e5e9467130de09b7810097c0b3779219ffe0.tar.gz
seven-wonders-c4d9e5e9467130de09b7810097c0b3779219ffe0.tar.bz2
seven-wonders-c4d9e5e9467130de09b7810097c0b3779219ffe0.zip
Fix SW client "request"
Diffstat (limited to 'sw-client/src/commonMain/kotlin/org')
-rw-r--r--sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt13
1 files changed, 10 insertions, 3 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 e13ab505..3dca33c1 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,5 +1,9 @@
package org.luxons.sevenwonders.client
+import kotlinx.coroutines.CoroutineStart
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.async
+import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first
import kotlinx.serialization.DeserializationStrategy
@@ -38,16 +42,19 @@ class SevenWondersClient {
}
}
+@OptIn(ExperimentalCoroutinesApi::class)
private suspend inline fun <reified T : Any, reified U : Any> StompSessionWithKxSerialization.request(
sendDestination: String,
receiveDestination: String,
payload: T? = null,
serializer: SerializationStrategy<T>,
deserializer: DeserializationStrategy<U>
-): U {
- val sub = subscribe(receiveDestination, deserializer)
+): U = coroutineScope {
+ val sub = async(start = CoroutineStart.UNDISPATCHED) {
+ subscribe(receiveDestination, deserializer).first()
+ }
convertAndSend(sendDestination, payload, serializer)
- return sub.first()
+ sub.await()
}
class SevenWondersSession(private val stompSession: StompSessionWithKxSerialization) {
bgstack15