We're currently utilizing DGS, and the majority of our source code is written in Kotlin. I'm exploring how to effectively use Kotlin coroutines within this context.
At present, my approach is to consider converting my coroutine jobs to CompletableFuture instances. However, I'm uncertain if this is the best practice or the most efficient method. Any insights or suggestions on this matter would be greatly appreciated.
@DgsComponent
class SampleDataFetcher {
@DgsQuery
fun greeting(): CompletableFuture<String> = dgsEndPoint{
delay(1000) // Simulate an asynchronous operation
"Hello, DGS with Kotlin Coroutines!"
}
}
fun <T> dgsEndPoint(block: suspend () -> T): CompletableFuture<T> {
// This is example code, but we can discuss on this one
return GlobalScope.future {
block()
}
}```