when writing a custom Dispatcher, is there a way t...
# coroutines
j
when writing a custom Dispatcher, is there a way to tell IntelliJ to not show warnings about
Copy code
Possibly blocking call in non-blocking context could lead to thread starvation
Dispatchers.IO somehow manages to make such warnings go away, I want to make those warnings go away for my custom dispatcher too
Copy code
launch(Dispatchers.CUSTOM) {
   println(Thread.currentThread())
   Thread.sleep(5_000) <<-- warning: Possibly blocking call ...
   delay(5_000)
   println("done!!!")
}
r
The JetBrains java-annotations library contains a
@BlockingExecutor
annotation that sounds like the thing you need. I haven't actually tried it to see if it fixes the IntelliJ warning, but it would surprise me if it didn't 😅 : https://javadoc.io/doc/org.jetbrains/annotations/latest/org/jetbrains/annotations/BlockingExecutor.html
j
that works, thanks!! there's also an @Language annotation in there so you can annotate for example doSomethingWithSQL(@Language("sql") sql: String) now whenever you call doSomethingWithSQL("SELECT * FROM ...") you get syntax highlighting I need to dig a bit more into that jetbrains annotations library, seems super useful!
r
Untitled.cpp
j
This is how I used it in my article: https://kt.academy/article/dispatcher-loom
Copy code
val Dispatchers.LOOM: @BlockingExecutor CoroutineDispatcher
    get() = Executors.newVirtualThreadPerTaskExecutor().asCoroutineDispatcher()
that looks like a Spring problem though
r
Yes dagger/hilt
118 Views