how do i sleep an app which is using coroutines an...
# ktor
o
how do i sleep an app which is using coroutines and ktor for say like 6 secs?
d
Do you mean preventing everything from working, or just to delay a request while it is serving other requests/doing other stuff?
If it is the second case, you can use
delay
from
kotlinx.coroutines
that should be already available if you are using ktor: https://github.com/Kotlin/kotlinx.coroutines#kotlinxcoroutines
o
ok let me try
no i want to sleep the whole app at tht point
is there a way?
d
You can Thread.sleep the current thread. But what’s the point/your usecase? Do you want to stop handling requests or what?
o
well, i have this loop where this bot uses ktor functions to receive data from the connection. So before it starts, it checks if it can connect to the address given by doing a while loop and trying to connect each time, then wait for a set amount of time. This waiting job has to be on the connection, but idk
c
You can install an interceptor that respond with 503 Service unavailable if the underlying service is down
o
could putting the entire loop inside a launch { } work?
c
and the loop should run asynchronously in a separate coroutine that could be started by launch
o
hmm let me try