Hi,
Is there a way to mark some function as blocking - so that the IDE will warn about using it inside suspending code?
I already know that if I am writing something like the following:
suspend fun example() {
Thread.sleep(1000)
}
then the IDE will warn me about “inappropriate blocking method call” because I am calling to the blocking method “sleep” in a suspending function.
what I am looking for is for a way to mark other methods as blocking, something like:
@Blocking
fun sleep1000() { Thread.sleep(1000) }
suspend fun nonBlocking() {
sleep1000() //here the ide will warn me about inappropriate usage
}
I did noticed that if I am marking the method as throwing InterruptedException Ill get the required behavior:
@Throws(InterruptedException::class)
fun sleep1000() { Thread.sleep(1000) }
suspend fun nonBlocking() {
sleep1000() //here the ide does warn me about inappropriate usage
}
But it seems more like a hack that takes advantage of the current implementation of this feature in Idea…