<@UFL90KYE5> - I just shifted my lauch3 just above...
# announcements
g
@Antanas A. - I just shifted my lauch3 just above coroutineScope{...} and it works just fine. But, surprisingly any thing below coroutineScope{...} is never gonna execute...!! It is blocking..! May be its a bug. I have no idea.!
g
People, could you please use threads, it's hard to follow discussion of other messages
👍 1
a
yes of course coroutineScope call is blocking (it is suspending your execution)
and blocks(suspends) until all children coroutines will be completed
so in your example you are launching new coroutine inside coroutineScope, and delaying 2seconds, then 2seconds, then MAX_VALUE
so that coroutine will never be completed
so your coroutineScope also never completes, because of parent-child relationships
so coroutineScope call will be blocked (suspended) and no execution would happen below that code
it's not related to runBlocking or anything
g
It would have made sense if
runBlocking
would have had not returned to main() as coroutineScope{...} continue execution. But, it's blocking even a expression below that.
isn't it a thread blocking?
a
could you explain what do you want to say?
you call "coroutineScope" will suspend execution until everything inside coroutineScope completes
thats why you do not get anything executed after coroutineScope
g
yes you are correct. but according to http://kotlinlang.org coroutineScope{...} will not block the current thread while waiting for all children to complete.
a
no, there are no any thread blocking
could you give me an URL to exact doc?
maybe you've misinterpreted something (or there are bug in docs)
go to Scope Builder section
a
" It creates new coroutine scope and does not complete until all launched children complete. "
it says what I've said
but
"The main difference between runBlocking and coroutineScope is that the latter does not block the current thread while waiting for all children to complete." Here I think where you've got confused
g
yes
please correct me
t
coroutineScope
is NOT blocking. It suspends as long as it has non-completed children coroutines, which is the case because it has a children coroutine (launch2) that delays for a very very long time. Note that
runBlocking
has nothing to do with that ; even without
runBlocking
, launch3 would have to wait until children of
coroutineScope
have completed before resuming execution and reaching launch3.
👍 1
a
to understand
runBlocking is function, and coroutineScope is suspend function if you'll call runBlocking anywhere inside code it will BLOCK current thread
if you'll run coroutineScope {} it will SUSPEND execution
but not a thread
g
ok. thank you very much. got it 🙂
a
the result feels the same, but mechanics is different
so I think you've observed that execution has stuck
And thought that thread has been blocked
hope it helps you to understand
g
exactly yea... thanks it is helpful to debug further.
Thanks buddy. All I did now is to put launch{1}, launch{3} inside coroutineScoope{..} and it is resuming its work now. 🙂
a
actually you don't need that coroutineScope at all, runBlocking itself will wait until all launches inside runBlocking will complete