Anders Sveen
11/17/2021, 10:44 AMlaunch(<http://Dispatchers.IO|Dispatchers.IO>) { ... }
It does return 200 fast, but wait with the payload till after launch completes. Any pointers on how to achieve this? 🙂Aleksei Tirman [JB]
11/17/2021, 10:46 AMAnders Sveen
11/17/2021, 10:46 AMAnders Sveen
11/17/2021, 10:46 AMAleksei Tirman [JB]
11/17/2021, 10:46 AMlaunch
call should work in that caseAleksei Tirman [JB]
11/17/2021, 10:47 AMAnders Sveen
11/17/2021, 10:51 AMpost("company") {
val company = companyService.create(call.receive<Company>())
println("Before")
launch(<http://Dispatchers.IO|Dispatchers.IO>) {
companyService.slowUpdateThing()
println("Inside")
}
println("After")
call.respond(HttpStatus.OK_200, company.id)
}
We get the sequence of:
• Before
• After
• 200OK Headers
• Inside
• Actual response payloadAleksei Tirman [JB]
11/17/2021, 11:13 AMInside
after some time:
fun main() {
embeddedServer(Netty, port = 3333) {
install(ContentNegotiation) {
json()
}
routing {
post("company") {
val company = call.receive<Company>()
println("Before")
launch(<http://Dispatchers.IO|Dispatchers.IO>) {
repeat(10) {
delay(500)
}
println("Inside")
}
println("After")
call.respondText { company.x.toString() }
}
}
}.start()
}
@Serializable
data class Company(val x: Int)
Aleksei Tirman [JB]
11/17/2021, 11:14 AMcompanyService
is used in both placesAnders Sveen
11/17/2021, 11:22 AMTrevor Stone
11/17/2021, 3:01 PMTrevor Stone
11/17/2021, 3:01 PMTrevor Stone
11/17/2021, 3:02 PMTrevor Stone
11/17/2021, 3:02 PMJacopo Franzoi
11/21/2021, 12:08 PMAnders Sveen
11/21/2021, 12:27 PM