https://kotlinlang.org logo
Title
j

jordigarcl

06/22/2020, 1:09 PM
Hi guys, this is a question of concept. Under which circumstances would it be beneficial to
launch
a single coroutine in a
runBlocking
scope? Example
fun foo() {
	runBlocking {
		launch {
			// some suspend functions
		}
	}
}
Instead of
fun foo() {
	runBlocking {
		// some suspend functions
	}
}
s

streetsofboston

06/22/2020, 1:14 PM
Just one launch, not much benefit. But if you do multiple launch-es, you can do stuff in parallel and have runBlocking return when they are all done.
j

jordigarcl

06/22/2020, 1:16 PM
That's what I thought. Is there any benefit for a single
launch
though?
a

andylamax

06/22/2020, 1:59 PM
There is no benefit at all for a single
launch
.
e

elizarov

06/22/2020, 2:54 PM
No benefit. A single
launch
inside
runBlocking
should be totally transparent.
a

andylamax

06/22/2020, 2:55 PM
The man himself hath spoken
😂 3
s

streetsofboston

06/22/2020, 2:58 PM
To be sure; a
runBlocking
with j*ust* a single
launch
is totally transparent, but it could still have one
launch
and some other code, which then would happen in parallel. 🙂
runBlocking {
    launch { .... }
    here() 
    is()
    someOtherCode()
}