diff options
Diffstat (limited to 'kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft')
-rw-r--r-- | kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt b/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt index 1e19f394..bc182467 100644 --- a/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt +++ b/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt @@ -22,8 +22,9 @@ package pl.treksoft.kvision.remote import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import kotlinx.coroutines.CoroutineStart import kotlinx.coroutines.Deferred -import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.GlobalScope import org.jooby.Kooby import org.jooby.Session @@ -64,8 +65,9 @@ actual typealias Profile = CommonProfile /** * A helper extension function for asynchronous request processing. */ +@UseExperimental(ExperimentalCoroutinesApi::class) fun <RESP> Request?.async(block: (Request) -> RESP): Deferred<RESP> = this?.let { req -> - GlobalScope.coroutinesAsync(Dispatchers.Unconfined) { + GlobalScope.coroutinesAsync(start = CoroutineStart.UNDISPATCHED) { block(req) } } ?: throw IllegalStateException("Request not set!") @@ -73,9 +75,10 @@ fun <RESP> Request?.async(block: (Request) -> RESP): Deferred<RESP> = this?.let /** * A helper extension function for asynchronous request processing with session. */ +@UseExperimental(ExperimentalCoroutinesApi::class) fun <RESP> Request?.asyncSession(block: (Request, Session) -> RESP): Deferred<RESP> = this?.let { req -> val session = req.session() - GlobalScope.coroutinesAsync(Dispatchers.Unconfined) { + GlobalScope.coroutinesAsync(start = CoroutineStart.UNDISPATCHED) { block(req, session) } } ?: throw IllegalStateException("Request not set!") @@ -83,11 +86,12 @@ fun <RESP> Request?.asyncSession(block: (Request, Session) -> RESP): Deferred<RE /** * A helper extension function for asynchronous request processing with session and user profile. */ +@UseExperimental(ExperimentalCoroutinesApi::class) fun <RESP> Request?.asyncAuth(block: (Request, Session, Profile) -> RESP): Deferred<RESP> = this?.let { req -> val session = req.session() val profile = req.require(CommonProfile::class.java) as CommonProfile? profile?.let { - GlobalScope.coroutinesAsync(Dispatchers.Unconfined) { + GlobalScope.coroutinesAsync(start = CoroutineStart.UNDISPATCHED) { block(req, session, profile) } } |