From c4d9e5e9467130de09b7810097c0b3779219ffe0 Mon Sep 17 00:00:00 2001 From: Joffrey Bion Date: Sun, 17 May 2020 18:22:23 +0200 Subject: Fix SW client "request" --- .../org/luxons/sevenwonders/client/SevenWondersClient.kt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'sw-client') 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 StompSessionWithKxSerialization.request( sendDestination: String, receiveDestination: String, payload: T? = null, serializer: SerializationStrategy, deserializer: DeserializationStrategy -): 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) { -- cgit