https://kotlinlang.org logo
#ktor
Title
# ktor
f

Fernando Sanchez (Perraco Labs)

03/11/2024, 8:41 AM
I am trying to understand why in a typical CRUD server I should mark the service and repository functions with suspend. As far as I understood, Ktor requests run in a Dispatcher.IO (?). If all my requests are Route - Service - Repository calls, what are the benefits in marking the service and repository functions with suspend? or using
withContext(<http://Dispatcher.IO|Dispatcher.IO>)
in the repository or service layer before performing IO operations? I know this would be beneficial if I had to execute for example multiple async tasks within the same request call, but this is not the case.
a

Antonio Acuña Prieto

03/11/2024, 9:00 AM
Related: https://kotlinlang.slack.com/archives/C0A974TJ9/p1710005378464099 As far as I know, if everything is running already on IO dispatcher which is meant to execute blocking operations, there is no benefit of doing what you said because it’s already there. But… I’m only trying to understand too so…