When using `thread` , the result is expected but w...
# getting-started
t
When using
thread
, the result is expected but when using
launch
from Kotlin coroutine, the result is wrong and not expected. Code: https://pl.kotl.in/cBD4j9XWb In the code, as expected when using the
thread
code in the for loop, the result prints 15000 but when using
launch
for loop, the result prints 0 !? which is not expected. Why is this happening and why
launch
is giving wrong answer?
e
you're blocking the executor with
Thread.sleep
.
delay
would give you the expected value.
but you should not be delaying and use
coroutineScope
or
join
instead.
also works
t
Thank you for the extra details. It works.