jvmusin
01/26/2021, 12:20 PMdelay
for some time (say 20 seconds) and then respond with a string.
I thought that when I call delay
, I can serve other requests while previous requests are suspended, but instead, I have to wait until those requests are done and only then I'm able to serve new requests.
How can I serve new requests when my previous requests are suspended? I thought it works like that by default, but now I really don't understand.Marc Knaup
01/26/2021, 12:46 PMJorge R
01/26/2021, 12:47 PMjvmusin
01/26/2021, 12:49 PMfun main() {
val req = AtomicInteger(0)
embeddedServer(Netty, port = 8081, host = "127.0.0.1") {
routing {
static("/static") {
resources()
}
get("/wait/{waitMillis}") {
val r = req.incrementAndGet()
log.debug("Got request $r")
val waitMillis = call.parameters["waitMillis"]!!.toLong()
delay(waitMillis)
call.respondText("Hello, i've waited for ${waitMillis}ms")
log.debug("Sent request $r")
}
}
}.start(wait = true)
}
Marc Knaup
01/26/2021, 12:50 PMjvmusin
01/26/2021, 12:50 PMwaitMillis
ms, but it processes requests almost one-by-onejvmusin
01/26/2021, 12:51 PMMarc Knaup
01/26/2021, 12:51 PMjvmusin
01/26/2021, 12:56 PM