ryan413
08/24/2020, 3:08 PMfun returnFuture(): CompleteableFuture<String> {
return runBlocking {
future {
// blocking code
"result"
}
}
}
or
fun returnFuture(): CompleteableFuture<String> {
return GlobalScope.future {
// blocking code
"result"
}
}
}
We have coroutine code further up the chain that then calls GraphQL-java, which in turn is wired with DataFetchers that implement an interface returning a CompleteableFuture. Ideally we want to share the same coroutine context throughout (so we can leverage MDC via MDCContext
, etc.)sikri
08/24/2020, 3:15 PMsikri
08/24/2020, 3:17 PMobject DomainScope : CoroutineScope
to at least limit global scope usageryan413
08/24/2020, 3:36 PMryan413
08/24/2020, 3:37 PMrunBlocking { future {} }
or GlobalScope.future {}
somewhere in there thoughryan413
08/24/2020, 3:38 PMDomainScope.future { /* ... */ }