strindberg
05/09/2026, 12:37 PMroute(UPLOAD_PATH) {
post {
call.receiveMultipart().forEachPart { part ->
if (part is PartData.FileItem) {
call.respond(
uploadService.store(part)
)
}
}
}
}
The stack is fully in ktor, so what uploadService.store() does contains no blocking code. In a code review it was suggested that this code still could be made more robust with wrapping it in a withContext(<http://Dispatchers.IO|Dispatchers.IO>) block like this:
route(UPLOAD_PATH) {
post {
withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
call.receiveMultipart().forEachPart { part ->
if (part is PartData.FileItem) {
call.respond(
uploadService.store(part)
)
}
}
}
}
}
Is this really necessary? My understanding of coroutines tells me that this is not an improvement when the stack is coroutines all the way down, but am I wrong?madisp
05/09/2026, 1:49 PMuploadService.store does not block then there's no need for IO indeedChrimaeon
05/09/2026, 4:59 PMstore is a suspend function, then the implementation of store is responsible to use the right dispatcher.