thhh
05/02/2021, 4:35 PMthread
, 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?ephemient
05/02/2021, 5:21 PMThread.sleep
. delay
would give you the expected value.ephemient
05/02/2021, 5:22 PMcoroutineScope
or join
instead.ephemient
05/02/2021, 5:25 PMephemient
05/02/2021, 5:25 PMthhh
05/02/2021, 5:33 PM