https://kotlinlang.org logo
Title
u

user

07/01/2022, 5:31 PM
What scope to use for launching a task in Kotlin from a controller? My Kotlin App is using Spring to expose an API that should execute a long task in the background. We need to return @PutMapping("/refresh") fun refresh() = { GlobalScope.launch(IO) { refreshDataFromCache() } return ResponseEntity.accepted().body("""{"result": "accepted"}""") } IntelliJ complains that using the GlobalScope is an anti-pattern. However, I cannot just add suspend to the controller function or it won't work. Neither I can use runBlocking or the method will need to wait...