Hi wonderful people, I'm wondering what's the diff...
# announcements
w
Hi wonderful people, I'm wondering what's the difference between those two lines of code:
Copy code
// First method
val test = Mono.just("hello").run { block() }

// Second method
val test = Mono.just("hello").block()
Both cases
test
has
String?
type
k
They're pretty much the same The only technical difference I can think of is that
block
in the first one doesn't have to be defined on the subject, it can be a top level function or something from the surrounding scope.
👍 1
w
@karelpeeters well actually IntelliJ says
inappropriate blocking method call
and it suggests to write it either using
run
or
with
k
when
? Are you sure? And is this in a coroutine context or something?
w
sorry I mean
with
@karelpeeters it's inside a method that returns a
Mono
k
Can you show a screenshot of some surrounding code including the warning?
w
@karelpeeters yeah sure here it is
k
Huh, where does
block
come from then?
w
it's from
Mono
according to the documentation
Copy code
* Subscribe to this {@link Mono} and <strong>block indefinitely</strong> until a next signal is
	 * received. Returns that value, or null if the Mono completes empty. In case the Mono
	 * errors, the original exception is thrown (wrapped in a {@link RuntimeException} if
	 * it was a checked exception).
k
Hmm that's really strange, I have no idea why
run
or
with
would help unless Mono has specific versions as well.
👍 1
w
thanks @karelpeeters
w
Isn’t this just IntelliJ inspection? I don’t think it has anything to do with compiler or anything really. It seems to me like writing
.run { block() }
isn’t detected by that particular inspection
You could go to settings->inspections, disable
inappropriate thread-blocking method call
and see if the warning goes away. The description says
Reports thread-blocking method calls found in a code fragment where a thread should not be blocked  (e.g. Reactive frameworks, Kotlin coroutines)
so there’s good chance it’s just IntelliJ being helpful and saying you shouldn’t be using blocking methods in reactive frameworks
k
But then why would using
run
or
with
help at all? They just shuffle parameter names around, they don't change anything about the blocking.
w
@karelpeeters I’d say the way inspection is implemented, it doesn’t detect such usage — it only recognizes e.g. calling
block
on
Mono
type, and not within
Mono
scope. I’d guess
.let { it.block() }
would also show a warning
k
But why would it suggests such a brittle way to supress the inspection instead of just
@Supress
?
🤔 1
w
I can’t seem to reproduce this warning in either AndroidStudio or IntelliJ 2019.2