is there a way to wait for not yet started corouti...
# coroutines
m
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
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
top-level
yield
o
yield
doesn't wait for anything though
m
thanks! Will checkout completable deffered
s
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
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
Coroutines try to stop being automagical beyond the
suspend
keyword :)
m
good point, I guess it's better to keep things simple 🙂