https://kotlinlang.org logo
#coroutines
Title
# coroutines
m

Maciek

03/24/2020, 6:55 AM
is there a way to wait for not yet started coroutine? I want to achieve something similar to
yield
but with the coroutine that'll be started in the future
o

octylFractal

03/24/2020, 6:57 AM
I don't get what you mean by something similar to
yield()
? are you talking about the Sequence
yield()
or the top-level
yield()
?
regardless, it sounds like you probably want to use
CompleteableDeferred
👍 1
m

Maciek

03/24/2020, 6:58 AM
top-level
yield
o

octylFractal

03/24/2020, 6:58 AM
yield
doesn't wait for anything though
m

Maciek

03/24/2020, 7:01 AM
thanks! Will checkout completable deffered
s

streetsofboston

03/24/2020, 11:39 AM
What about a call to
CoroutineScope.async(start=LAZY)
? This will return a
Deferred<T>
and the Coroutine won't yet be running. It will start only after calling
await()
,
start()
(and some other methods) on it. https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/async.html
👍 1
m

Maciek

03/24/2020, 11:54 AM
oo that's cool, it's really close to something that I wanted to achieve, thanks! I was trying to avoid having some handle/object on coroutine that needs to do the waiting and was wondering if it can be automagically done through some await or yield mechanism under the hood. But I guess it's close enough
b

bdawg.io

03/24/2020, 4:28 PM
Coroutines try to stop being automagical beyond the
suspend
keyword :)
m

Maciek

03/24/2020, 5:43 PM
good point, I guess it's better to keep things simple 🙂
2 Views