https://kotlinlang.org logo
#coroutines
Title
# coroutines
s

spand

11/10/2020, 10:15 AM
Can I mark my methods as blocking to opt-in to the "inappropriate blocking call" warning somehow?
b

Big Chungus

11/10/2020, 10:28 AM
Why can't you just dispatch them on Dispatchers.IO?
s

spand

11/10/2020, 10:31 AM
That would be step 2
Also, I cannot get rid of them so to prevent further accidental blocking calls in suspending functionss
b

Big Chungus

11/10/2020, 10:51 AM
No I mean Dispatchers.IO are meant for blocking calls
So
Copy code
suspend fun myFun() {
  someSuspendFun()
  launch(<http://Dispatchers.IO|Dispatchers.IO>) { someBlockingFun() }
}
s

spand

11/10/2020, 10:56 AM
Yes I am well aware. I want a warning when I or someone else forgets to do it
b

Big Chungus

11/10/2020, 11:01 AM
Oooh, i totally misunderstood you issue. Apologies. 😀
You can add RequiresOptIn annotation
l

louiscad

11/10/2020, 11:06 AM
You can add
@Throws(IOException::class)
I think, it should be an okayish workaround. @elizarov Do you think declaring potentially long blocking functions could land in Kotlin at some point? I'd use a way to declare if a function does significant CPU work or blocking I/O. Such a thing could propagate similarly to
@RequiresOptIn
annotated annotations (with warning or error), until stopped manually or automatically at the relevant dispatcher switch (using the invoke operator,
withContext
or explicit dispatcher injection e.g. in a
launch
call).
c

CLOVIS

11/10/2020, 11:47 AM
Is there a way to tell the IDE to not display that warning inside a
withContext(IO)
?
s

spand

11/10/2020, 11:52 AM
It happens by default
Unless you are talking about the
@RequiesOptIn
way
c

CLOVIS

11/10/2020, 12:00 PM
Not for me... I have to tell IntelliJ to ignore all calls one by one, it's really not fun
s

spand

11/10/2020, 12:07 PM
You should report it. I had a similar bug that was fixed very fast.
2 Views