diff options
Diffstat (limited to 'src/main')
5 files changed, 106 insertions, 112 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/remote/JoobyRemoteAgent.kt b/src/main/kotlin/pl/treksoft/kvision/remote/JoobyRemoteAgent.kt index 30d2062d..318f77ea 100644 --- a/src/main/kotlin/pl/treksoft/kvision/remote/JoobyRemoteAgent.kt +++ b/src/main/kotlin/pl/treksoft/kvision/remote/JoobyRemoteAgent.kt @@ -21,7 +21,6 @@ */ package pl.treksoft.kvision.remote -import kotlinx.coroutines.Deferred import kotlinx.coroutines.asDeferred import kotlinx.serialization.ImplicitReflectionSerializer import kotlinx.serialization.list @@ -43,7 +42,7 @@ open class JoobyRemoteAgent<T : Any>(val serviceManager: JoobyServiceManager<T>) /** * Executes defined call to a remote web service. */ - inline fun <reified RET : Any, T> call(noinline function: T.(Request?) -> Deferred<RET>): Deferred<RET> { + suspend inline fun <reified RET : Any, T> call(noinline function: suspend T.(Request?) -> RET): RET { val (url, method) = serviceManager.getCalls()[function.toString()] ?: throw IllegalStateException("Function not specified!") return callAgent.jsonRpcCall(url, method = method).then { @@ -58,15 +57,15 @@ open class JoobyRemoteAgent<T : Any>(val serviceManager: JoobyServiceManager<T>) JSON.nonstrict.parse(RET::class.serializer(), it) } } - }.asDeferred() + }.asDeferred().await() } /** * Executes defined call to a remote web service. */ - inline fun <reified RET : Any, T> call( - noinline function: T.(Request?) -> Deferred<List<RET>> - ): Deferred<List<RET>> { + suspend inline fun <reified RET : Any, T> call( + noinline function: suspend T.(Request?) -> List<RET> + ): List<RET> { val (url, method) = serviceManager.getCalls()[function.toString()] ?: throw IllegalStateException("Function not specified!") return callAgent.jsonRpcCall(url, method = method).then { @@ -80,15 +79,15 @@ open class JoobyRemoteAgent<T : Any>(val serviceManager: JoobyServiceManager<T>) JSON.nonstrict.parse(RET::class.serializer().list, it) } } - }.asDeferred() + }.asDeferred().await() } /** * Executes defined call to a remote web service. */ - inline fun <reified PAR, reified RET : Any, T> call( - noinline function: T.(PAR, Request?) -> Deferred<RET>, p: PAR - ): Deferred<RET> { + suspend inline fun <reified PAR, reified RET : Any, T> call( + noinline function: suspend T.(PAR, Request?) -> RET, p: PAR + ): RET { val data = serialize(p) val (url, method) = serviceManager.getCalls()[function.toString()] ?: throw IllegalStateException("Function not specified!") @@ -104,15 +103,15 @@ open class JoobyRemoteAgent<T : Any>(val serviceManager: JoobyServiceManager<T>) JSON.nonstrict.parse(RET::class.serializer(), it) } } - }.asDeferred() + }.asDeferred().await() } /** * Executes defined call to a remote web service. */ - inline fun <reified PAR, reified RET : Any, T> call( - noinline function: T.(PAR, Request?) -> Deferred<List<RET>>, p: PAR - ): Deferred<List<RET>> { + suspend inline fun <reified PAR, reified RET : Any, T> call( + noinline function: suspend T.(PAR, Request?) -> List<RET>, p: PAR + ): List<RET> { val data = serialize(p) val (url, method) = serviceManager.getCalls()[function.toString()] ?: throw IllegalStateException("Function not specified!") @@ -127,15 +126,15 @@ open class JoobyRemoteAgent<T : Any>(val serviceManager: JoobyServiceManager<T>) JSON.nonstrict.parse(RET::class.serializer().list, it) } } - }.asDeferred() + }.asDeferred().await() } /** * Executes defined call to a remote web service. */ - inline fun <reified PAR1, reified PAR2, reified RET : Any, T> call( - noinline function: T.(PAR1, PAR2, Request?) -> Deferred<RET>, p1: PAR1, p2: PAR2 - ): Deferred<RET> { + suspend inline fun <reified PAR1, reified PAR2, reified RET : Any, T> call( + noinline function: suspend T.(PAR1, PAR2, Request?) -> RET, p1: PAR1, p2: PAR2 + ): RET { val data1 = serialize(p1) val data2 = serialize(p2) val (url, method) = @@ -152,15 +151,15 @@ open class JoobyRemoteAgent<T : Any>(val serviceManager: JoobyServiceManager<T>) JSON.nonstrict.parse(RET::class.serializer(), it) } } - }.asDeferred() + }.asDeferred().await() } /** * Executes defined call to a remote web service. */ - inline fun <reified PAR1, reified PAR2, reified RET : Any, T> call( - noinline function: T.(PAR1, PAR2, Request?) -> Deferred<List<RET>>, p1: PAR1, p2: PAR2 - ): Deferred<List<RET>> { + suspend inline fun <reified PAR1, reified PAR2, reified RET : Any, T> call( + noinline function: suspend T.(PAR1, PAR2, Request?) -> List<RET>, p1: PAR1, p2: PAR2 + ): List<RET> { val data1 = serialize(p1) val data2 = serialize(p2) val (url, method) = @@ -176,15 +175,15 @@ open class JoobyRemoteAgent<T : Any>(val serviceManager: JoobyServiceManager<T>) JSON.nonstrict.parse(RET::class.serializer().list, it) } } - }.asDeferred() + }.asDeferred().await() } /** * Executes defined call to a remote web service. */ - inline fun <reified PAR1, reified PAR2, reified PAR3, reified RET : Any, T> call( - noinline function: T.(PAR1, PAR2, PAR3, Request?) -> Deferred<RET>, p1: PAR1, p2: PAR2, p3: PAR3 - ): Deferred<RET> { + suspend inline fun <reified PAR1, reified PAR2, reified PAR3, reified RET : Any, T> call( + noinline function: suspend T.(PAR1, PAR2, PAR3, Request?) -> RET, p1: PAR1, p2: PAR2, p3: PAR3 + ): RET { val data1 = serialize(p1) val data2 = serialize(p2) val data3 = serialize(p3) @@ -202,15 +201,15 @@ open class JoobyRemoteAgent<T : Any>(val serviceManager: JoobyServiceManager<T>) JSON.nonstrict.parse(RET::class.serializer(), it) } } - }.asDeferred() + }.asDeferred().await() } /** * Executes defined call to a remote web service. */ - inline fun <reified PAR1, reified PAR2, reified PAR3, reified RET : Any, T> call( - noinline function: T.(PAR1, PAR2, PAR3, Request?) -> Deferred<List<RET>>, p1: PAR1, p2: PAR2, p3: PAR3 - ): Deferred<List<RET>> { + suspend inline fun <reified PAR1, reified PAR2, reified PAR3, reified RET : Any, T> call( + noinline function: suspend T.(PAR1, PAR2, PAR3, Request?) -> List<RET>, p1: PAR1, p2: PAR2, p3: PAR3 + ): List<RET> { val data1 = serialize(p1) val data2 = serialize(p2) val data3 = serialize(p3) @@ -227,15 +226,15 @@ open class JoobyRemoteAgent<T : Any>(val serviceManager: JoobyServiceManager<T>) JSON.nonstrict.parse(RET::class.serializer().list, it) } } - }.asDeferred() + }.asDeferred().await() } /** * Executes defined call to a remote web service. */ - inline fun <reified PAR1, reified PAR2, reified PAR3, reified PAR4, reified RET : Any, T> call( - noinline function: T.(PAR1, PAR2, PAR3, PAR4, Request?) -> Deferred<RET>, p1: PAR1, p2: PAR2, p3: PAR3, p4: PAR4 - ): Deferred<RET> { + suspend inline fun <reified PAR1, reified PAR2, reified PAR3, reified PAR4, reified RET : Any, T> call( + noinline function: suspend T.(PAR1, PAR2, PAR3, PAR4, Request?) -> RET, p1: PAR1, p2: PAR2, p3: PAR3, p4: PAR4 + ): RET { val data1 = serialize(p1) val data2 = serialize(p2) val data3 = serialize(p3) @@ -254,19 +253,19 @@ open class JoobyRemoteAgent<T : Any>(val serviceManager: JoobyServiceManager<T>) JSON.nonstrict.parse(RET::class.serializer(), it) } } - }.asDeferred() + }.asDeferred().await() } /** * Executes defined call to a remote web service. */ - inline fun <reified PAR1, reified PAR2, reified PAR3, reified PAR4, reified RET : Any, T> call( - noinline function: T.(PAR1, PAR2, PAR3, PAR4, Request?) -> Deferred<List<RET>>, + suspend inline fun <reified PAR1, reified PAR2, reified PAR3, reified PAR4, reified RET : Any, T> call( + noinline function: suspend T.(PAR1, PAR2, PAR3, PAR4, Request?) -> List<RET>, p1: PAR1, p2: PAR2, p3: PAR3, p4: PAR4 - ): Deferred<List<RET>> { + ): List<RET> { val data1 = serialize(p1) val data2 = serialize(p2) val data3 = serialize(p3) @@ -284,22 +283,22 @@ open class JoobyRemoteAgent<T : Any>(val serviceManager: JoobyServiceManager<T>) JSON.nonstrict.parse(RET::class.serializer().list, it) } } - }.asDeferred() + }.asDeferred().await() } /** * Executes defined call to a remote web service. */ @Suppress("LongParameterList") - inline fun <reified PAR1, reified PAR2, reified PAR3, reified PAR4, reified PAR5, + suspend inline fun <reified PAR1, reified PAR2, reified PAR3, reified PAR4, reified PAR5, reified RET : Any, T> call( - noinline function: T.(PAR1, PAR2, PAR3, PAR4, PAR5, Request?) -> Deferred<RET>, + noinline function: suspend T.(PAR1, PAR2, PAR3, PAR4, PAR5, Request?) -> RET, p1: PAR1, p2: PAR2, p3: PAR3, p4: PAR4, p5: PAR5 - ): Deferred<RET> { + ): RET { val data1 = serialize(p1) val data2 = serialize(p2) val data3 = serialize(p3) @@ -319,22 +318,22 @@ open class JoobyRemoteAgent<T : Any>(val serviceManager: JoobyServiceManager<T>) JSON.nonstrict.parse(RET::class.serializer(), it) } } - }.asDeferred() + }.asDeferred().await() } /** * Executes defined call to a remote web service. */ @Suppress("LongParameterList") - inline fun <reified PAR1, reified PAR2, reified PAR3, reified PAR4, reified PAR5, + suspend inline fun <reified PAR1, reified PAR2, reified PAR3, reified PAR4, reified PAR5, reified RET : Any, T> call( - noinline function: T.(PAR1, PAR2, PAR3, PAR4, PAR5, Request?) -> Deferred<List<RET>>, + noinline function: suspend T.(PAR1, PAR2, PAR3, PAR4, PAR5, Request?) -> List<RET>, p1: PAR1, p2: PAR2, p3: PAR3, p4: PAR4, p5: PAR5 - ): Deferred<List<RET>> { + ): List<RET> { val data1 = serialize(p1) val data2 = serialize(p2) val data3 = serialize(p3) @@ -353,7 +352,7 @@ open class JoobyRemoteAgent<T : Any>(val serviceManager: JoobyServiceManager<T>) JSON.nonstrict.parse(RET::class.serializer().list, it) } } - }.asDeferred() + }.asDeferred().await() } diff --git a/src/main/kotlin/pl/treksoft/kvision/remote/JoobyServiceManager.kt b/src/main/kotlin/pl/treksoft/kvision/remote/JoobyServiceManager.kt index c9d8ba25..0d3515a1 100644 --- a/src/main/kotlin/pl/treksoft/kvision/remote/JoobyServiceManager.kt +++ b/src/main/kotlin/pl/treksoft/kvision/remote/JoobyServiceManager.kt @@ -21,8 +21,6 @@ */ package pl.treksoft.kvision.remote -import kotlinx.coroutines.Deferred - /** * Multiplatform service manager for Jooby. */ @@ -38,7 +36,7 @@ actual open class JoobyServiceManager<T : Any> actual constructor(service: T) : * @param method a HTTP method */ protected actual inline fun <reified RET> bind( - noinline function: T.(Request?) -> Deferred<RET>, + noinline function: suspend T.(Request?) -> RET, route: String?, method: RpcHttpMethod ) { val routeDef = route ?: "route${this::class.simpleName}${counter++}" @@ -52,7 +50,7 @@ actual open class JoobyServiceManager<T : Any> actual constructor(service: T) : * @param method a HTTP method */ protected actual inline fun <reified PAR, reified RET> bind( - noinline function: T.(PAR, Request?) -> Deferred<RET>, + noinline function: suspend T.(PAR, Request?) -> RET, route: String?, method: RpcHttpMethod ) { val routeDef = route ?: "route${this::class.simpleName}${counter++}" @@ -66,7 +64,7 @@ actual open class JoobyServiceManager<T : Any> actual constructor(service: T) : * @param method a HTTP method */ protected actual inline fun <reified PAR1, reified PAR2, reified RET> bind( - noinline function: T.(PAR1, PAR2, Request?) -> Deferred<RET>, + noinline function: suspend T.(PAR1, PAR2, Request?) -> RET, route: String?, method: RpcHttpMethod ) { val routeDef = route ?: "route${this::class.simpleName}${counter++}" @@ -80,7 +78,7 @@ actual open class JoobyServiceManager<T : Any> actual constructor(service: T) : * @param method a HTTP method */ protected actual inline fun <reified PAR1, reified PAR2, reified PAR3, reified RET> bind( - noinline function: T.(PAR1, PAR2, PAR3, Request?) -> Deferred<RET>, + noinline function: suspend T.(PAR1, PAR2, PAR3, Request?) -> RET, route: String?, method: RpcHttpMethod ) { val routeDef = route ?: "route${this::class.simpleName}${counter++}" @@ -94,7 +92,7 @@ actual open class JoobyServiceManager<T : Any> actual constructor(service: T) : * @param method a HTTP method */ protected actual inline fun <reified PAR1, reified PAR2, reified PAR3, reified PAR4, reified RET> bind( - noinline function: T.(PAR1, PAR2, PAR3, PAR4, Request?) -> Deferred<RET>, + noinline function: suspend T.(PAR1, PAR2, PAR3, PAR4, Request?) -> RET, route: String?, method: RpcHttpMethod ) { val routeDef = route ?: "route${this::class.simpleName}${counter++}" @@ -109,7 +107,7 @@ actual open class JoobyServiceManager<T : Any> actual constructor(service: T) : */ protected actual inline fun <reified PAR1, reified PAR2, reified PAR3, reified PAR4, reified PAR5, reified RET> bind( - noinline function: T.(PAR1, PAR2, PAR3, PAR4, PAR5, Request?) -> Deferred<RET>, + noinline function: suspend T.(PAR1, PAR2, PAR3, PAR4, PAR5, Request?) -> RET, route: String?, method: RpcHttpMethod ) { diff --git a/src/main/kotlin/pl/treksoft/kvision/remote/Security.kt b/src/main/kotlin/pl/treksoft/kvision/remote/Security.kt index bf77a06b..b485e17d 100644 --- a/src/main/kotlin/pl/treksoft/kvision/remote/Security.kt +++ b/src/main/kotlin/pl/treksoft/kvision/remote/Security.kt @@ -21,7 +21,6 @@ */ package pl.treksoft.kvision.remote -import kotlinx.coroutines.Deferred import kotlinx.coroutines.asDeferred import kotlinx.serialization.Serializable import pl.treksoft.kvision.utils.obj @@ -47,12 +46,12 @@ class LoginService { * Login with Pac4j FormClient. * @param credentials username and password credentials */ - fun login(credentials: Credentials?): Deferred<Boolean> = + suspend fun login(credentials: Credentials?): Boolean = if (credentials?.username != null) { loginAgent.remoteCall("callback?client_name=FormClient", obj { this.username = credentials.username this.password = credentials.password - }, HttpMethod.POST, "application/x-www-form-urlencoded").then { _: dynamic -> true }.asDeferred() + }, HttpMethod.POST, "application/x-www-form-urlencoded").then { _: dynamic -> true }.asDeferred().await() } else { throw SecurityException("Credentials cannot be empty") } diff --git a/src/main/kotlin/pl/treksoft/kvision/remote/SpringRemoteAgent.kt b/src/main/kotlin/pl/treksoft/kvision/remote/SpringRemoteAgent.kt index f329d10e..fea16b99 100644 --- a/src/main/kotlin/pl/treksoft/kvision/remote/SpringRemoteAgent.kt +++ b/src/main/kotlin/pl/treksoft/kvision/remote/SpringRemoteAgent.kt @@ -21,7 +21,6 @@ */ package pl.treksoft.kvision.remote -import kotlinx.coroutines.Deferred import kotlinx.coroutines.asDeferred import kotlinx.serialization.ImplicitReflectionSerializer import kotlinx.serialization.list @@ -43,7 +42,7 @@ open class SpringRemoteAgent<T : Any>(val serviceManager: SpringServiceManager<T /** * Executes defined call to a remote web service. */ - inline fun <reified RET : Any, T> call(noinline function: T.() -> Deferred<RET>): Deferred<RET> { + suspend inline fun <reified RET : Any, T> call(noinline function: suspend T.() -> RET): RET { val (url, method) = serviceManager.getCalls()[function.toString()] ?: throw IllegalStateException("Function not specified!") return callAgent.jsonRpcCall(url, method = method).then { @@ -58,15 +57,15 @@ open class SpringRemoteAgent<T : Any>(val serviceManager: SpringServiceManager<T JSON.nonstrict.parse(RET::class.serializer(), it) } } - }.asDeferred() + }.asDeferred().await() } /** * Executes defined call to a remote web service. */ - inline fun <reified RET : Any, T> call( - noinline function: T.() -> Deferred<List<RET>> - ): Deferred<List<RET>> { + suspend inline fun <reified RET : Any, T> call( + noinline function: suspend T.() -> List<RET> + ): List<RET> { val (url, method) = serviceManager.getCalls()[function.toString()] ?: throw IllegalStateException("Function not specified!") return callAgent.jsonRpcCall(url, method = method).then { @@ -80,15 +79,15 @@ open class SpringRemoteAgent<T : Any>(val serviceManager: SpringServiceManager<T JSON.nonstrict.parse(RET::class.serializer().list, it) } } - }.asDeferred() + }.asDeferred().await() } /** * Executes defined call to a remote web service. */ - inline fun <reified PAR, reified RET : Any, T> call( - noinline function: T.(PAR) -> Deferred<RET>, p: PAR - ): Deferred<RET> { + suspend inline fun <reified PAR, reified RET : Any, T> call( + noinline function: suspend T.(PAR) -> RET, p: PAR + ): RET { val data = serialize(p) val (url, method) = serviceManager.getCalls()[function.toString()] ?: throw IllegalStateException("Function not specified!") @@ -104,15 +103,15 @@ open class SpringRemoteAgent<T : Any>(val serviceManager: SpringServiceManager<T JSON.nonstrict.parse(RET::class.serializer(), it) } } - }.asDeferred() + }.asDeferred().await() } /** * Executes defined call to a remote web service. */ - inline fun <reified PAR, reified RET : Any, T> call( - noinline function: T.(PAR) -> Deferred<List<RET>>, p: PAR - ): Deferred<List<RET>> { + suspend inline fun <reified PAR, reified RET : Any, T> call( + noinline function: suspend T.(PAR) -> List<RET>, p: PAR + ): List<RET> { val data = serialize(p) val (url, method) = serviceManager.getCalls()[function.toString()] ?: throw IllegalStateException("Function not specified!") @@ -127,15 +126,15 @@ open class SpringRemoteAgent<T : Any>(val serviceManager: SpringServiceManager<T JSON.nonstrict.parse(RET::class.serializer().list, it) } } - }.asDeferred() + }.asDeferred().await() } /** * Executes defined call to a remote web service. */ - inline fun <reified PAR1, reified PAR2, reified RET : Any, T> call( - noinline function: T.(PAR1, PAR2) -> Deferred<RET>, p1: PAR1, p2: PAR2 - ): Deferred<RET> { + suspend inline fun <reified PAR1, reified PAR2, reified RET : Any, T> call( + noinline function: suspend T.(PAR1, PAR2) -> RET, p1: PAR1, p2: PAR2 + ): RET { val data1 = serialize(p1) val data2 = serialize(p2) val (url, method) = @@ -152,15 +151,15 @@ open class SpringRemoteAgent<T : Any>(val serviceManager: SpringServiceManager<T JSON.nonstrict.parse(RET::class.serializer(), it) } } - }.asDeferred() + }.asDeferred().await() } /** * Executes defined call to a remote web service. */ - inline fun <reified PAR1, reified PAR2, reified RET : Any, T> call( - noinline function: T.(PAR1, PAR2) -> Deferred<List<RET>>, p1: PAR1, p2: PAR2 - ): Deferred<List<RET>> { + suspend inline fun <reified PAR1, reified PAR2, reified RET : Any, T> call( + noinline function: suspend T.(PAR1, PAR2) -> List<RET>, p1: PAR1, p2: PAR2 + ): List<RET> { val data1 = serialize(p1) val data2 = serialize(p2) val (url, method) = @@ -176,15 +175,15 @@ open class SpringRemoteAgent<T : Any>(val serviceManager: SpringServiceManager<T JSON.nonstrict.parse(RET::class.serializer().list, it) } } - }.asDeferred() + }.asDeferred().await() } /** * Executes defined call to a remote web service. */ - inline fun <reified PAR1, reified PAR2, reified PAR3, reified RET : Any, T> call( - noinline function: T.(PAR1, PAR2, PAR3) -> Deferred<RET>, p1: PAR1, p2: PAR2, p3: PAR3 - ): Deferred<RET> { + suspend inline fun <reified PAR1, reified PAR2, reified PAR3, reified RET : Any, T> call( + noinline function: suspend T.(PAR1, PAR2, PAR3) -> RET, p1: PAR1, p2: PAR2, p3: PAR3 + ): RET { val data1 = serialize(p1) val data2 = serialize(p2) val data3 = serialize(p3) @@ -202,15 +201,15 @@ open class SpringRemoteAgent<T : Any>(val serviceManager: SpringServiceManager<T JSON.nonstrict.parse(RET::class.serializer(), it) } } - }.asDeferred() + }.asDeferred().await() } /** * Executes defined call to a remote web service. */ - inline fun <reified PAR1, reified PAR2, reified PAR3, reified RET : Any, T> call( - noinline function: T.(PAR1, PAR2, PAR3) -> Deferred<List<RET>>, p1: PAR1, p2: PAR2, p3: PAR3 - ): Deferred<List<RET>> { + suspend inline fun <reified PAR1, reified PAR2, reified PAR3, reified RET : Any, T> call( + noinline function: suspend T.(PAR1, PAR2, PAR3) -> List<RET>, p1: PAR1, p2: PAR2, p3: PAR3 + ): List<RET> { val data1 = serialize(p1) val data2 = serialize(p2) val data3 = serialize(p3) @@ -227,15 +226,15 @@ open class SpringRemoteAgent<T : Any>(val serviceManager: SpringServiceManager<T JSON.nonstrict.parse(RET::class.serializer().list, it) } } - }.asDeferred() + }.asDeferred().await() } /** * Executes defined call to a remote web service. */ - inline fun <reified PAR1, reified PAR2, reified PAR3, reified PAR4, reified RET : Any, T> call( - noinline function: T.(PAR1, PAR2, PAR3, PAR4) -> Deferred<RET>, p1: PAR1, p2: PAR2, p3: PAR3, p4: PAR4 - ): Deferred<RET> { + suspend inline fun <reified PAR1, reified PAR2, reified PAR3, reified PAR4, reified RET : Any, T> call( + noinline function: suspend T.(PAR1, PAR2, PAR3, PAR4) -> RET, p1: PAR1, p2: PAR2, p3: PAR3, p4: PAR4 + ): RET { val data1 = serialize(p1) val data2 = serialize(p2) val data3 = serialize(p3) @@ -254,19 +253,19 @@ open class SpringRemoteAgent<T : Any>(val serviceManager: SpringServiceManager<T JSON.nonstrict.parse(RET::class.serializer(), it) } } - }.asDeferred() + }.asDeferred().await() } /** * Executes defined call to a remote web service. */ - inline fun <reified PAR1, reified PAR2, reified PAR3, reified PAR4, reified RET : Any, T> call( - noinline function: T.(PAR1, PAR2, PAR3, PAR4) -> Deferred<List<RET>>, + suspend inline fun <reified PAR1, reified PAR2, reified PAR3, reified PAR4, reified RET : Any, T> call( + noinline function: suspend T.(PAR1, PAR2, PAR3, PAR4) -> List<RET>, p1: PAR1, p2: PAR2, p3: PAR3, p4: PAR4 - ): Deferred<List<RET>> { + ): List<RET> { val data1 = serialize(p1) val data2 = serialize(p2) val data3 = serialize(p3) @@ -284,22 +283,22 @@ open class SpringRemoteAgent<T : Any>(val serviceManager: SpringServiceManager<T JSON.nonstrict.parse(RET::class.serializer().list, it) } } - }.asDeferred() + }.asDeferred().await() } /** * Executes defined call to a remote web service. */ @Suppress("LongParameterList") - inline fun <reified PAR1, reified PAR2, reified PAR3, reified PAR4, reified PAR5, + suspend inline fun <reified PAR1, reified PAR2, reified PAR3, reified PAR4, reified PAR5, reified RET : Any, T> call( - noinline function: T.(PAR1, PAR2, PAR3, PAR4, PAR5) -> Deferred<RET>, + noinline function: suspend T.(PAR1, PAR2, PAR3, PAR4, PAR5) -> RET, p1: PAR1, p2: PAR2, p3: PAR3, p4: PAR4, p5: PAR5 - ): Deferred<RET> { + ): RET { val data1 = serialize(p1) val data2 = serialize(p2) val data3 = serialize(p3) @@ -319,22 +318,22 @@ open class SpringRemoteAgent<T : Any>(val serviceManager: SpringServiceManager<T JSON.nonstrict.parse(RET::class.serializer(), it) } } - }.asDeferred() + }.asDeferred().await() } /** * Executes defined call to a remote web service. */ @Suppress("LongParameterList") - inline fun <reified PAR1, reified PAR2, reified PAR3, reified PAR4, reified PAR5, + suspend inline fun <reified PAR1, reified PAR2, reified PAR3, reified PAR4, reified PAR5, reified RET : Any, T> call( - noinline function: T.(PAR1, PAR2, PAR3, PAR4, PAR5) -> Deferred<List<RET>>, + noinline function: suspend T.(PAR1, PAR2, PAR3, PAR4, PAR5) -> List<RET>, p1: PAR1, p2: PAR2, p3: PAR3, p4: PAR4, p5: PAR5 - ): Deferred<List<RET>> { + ): List<RET> { val data1 = serialize(p1) val data2 = serialize(p2) val data3 = serialize(p3) @@ -353,7 +352,7 @@ open class SpringRemoteAgent<T : Any>(val serviceManager: SpringServiceManager<T JSON.nonstrict.parse(RET::class.serializer().list, it) } } - }.asDeferred() + }.asDeferred().await() } diff --git a/src/main/kotlin/pl/treksoft/kvision/remote/SpringServiceManager.kt b/src/main/kotlin/pl/treksoft/kvision/remote/SpringServiceManager.kt index 6b26da8e..524347d7 100644 --- a/src/main/kotlin/pl/treksoft/kvision/remote/SpringServiceManager.kt +++ b/src/main/kotlin/pl/treksoft/kvision/remote/SpringServiceManager.kt @@ -21,7 +21,6 @@ */ package pl.treksoft.kvision.remote -import kotlinx.coroutines.Deferred import kotlin.reflect.KClass /** @@ -39,7 +38,7 @@ actual open class SpringServiceManager<T : Any> actual constructor(serviceClass: * @param method a HTTP method */ protected actual inline fun <reified RET> bind( - noinline function: T.() -> Deferred<RET>, + noinline function: suspend T.() -> RET, route: String?, method: RpcHttpMethod ) { val routeDef = route ?: "route${this::class.simpleName}${counter++}" @@ -53,7 +52,7 @@ actual open class SpringServiceManager<T : Any> actual constructor(serviceClass: * @param method a HTTP method */ protected actual inline fun <reified PAR, reified RET> bind( - noinline function: T.(PAR) -> Deferred<RET>, + noinline function: suspend T.(PAR) -> RET, route: String?, method: RpcHttpMethod ) { val routeDef = route ?: "route${this::class.simpleName}${counter++}" @@ -67,7 +66,7 @@ actual open class SpringServiceManager<T : Any> actual constructor(serviceClass: * @param method a HTTP method */ protected actual inline fun <reified PAR1, reified PAR2, reified RET> bind( - noinline function: T.(PAR1, PAR2) -> Deferred<RET>, + noinline function: suspend T.(PAR1, PAR2) -> RET, route: String?, method: RpcHttpMethod ) { val routeDef = route ?: "route${this::class.simpleName}${counter++}" @@ -81,7 +80,7 @@ actual open class SpringServiceManager<T : Any> actual constructor(serviceClass: * @param method a HTTP method */ protected actual inline fun <reified PAR1, reified PAR2, reified PAR3, reified RET> bind( - noinline function: T.(PAR1, PAR2, PAR3) -> Deferred<RET>, + noinline function: suspend T.(PAR1, PAR2, PAR3) -> RET, route: String?, method: RpcHttpMethod ) { val routeDef = route ?: "route${this::class.simpleName}${counter++}" @@ -95,7 +94,7 @@ actual open class SpringServiceManager<T : Any> actual constructor(serviceClass: * @param method a HTTP method */ protected actual inline fun <reified PAR1, reified PAR2, reified PAR3, reified PAR4, reified RET> bind( - noinline function: T.(PAR1, PAR2, PAR3, PAR4) -> Deferred<RET>, + noinline function: suspend T.(PAR1, PAR2, PAR3, PAR4) -> RET, route: String?, method: RpcHttpMethod ) { val routeDef = route ?: "route${this::class.simpleName}${counter++}" @@ -110,7 +109,7 @@ actual open class SpringServiceManager<T : Any> actual constructor(serviceClass: */ protected actual inline fun <reified PAR1, reified PAR2, reified PAR3, reified PAR4, reified PAR5, reified RET> bind( - noinline function: T.(PAR1, PAR2, PAR3, PAR4, PAR5) -> Deferred<RET>, + noinline function: suspend T.(PAR1, PAR2, PAR3, PAR4, PAR5) -> RET, route: String?, method: RpcHttpMethod ) { |