``` val one = GlobalScope.async(start = Corouti...
# coroutines
h
Copy code
val one = GlobalScope.async(start = CoroutineStart.LAZY) { A() }
    val two = GlobalScope.async(start = CoroutineStart.LAZY) { B() }

    one.start()
    Thread.sleep(1000)
    two.start()
is there a better way to wait for
one
to start first before starting
two
without using Thread.sleep in between?
s
If you want to wait for
two
to start until
A()
is done then you can just do
one.join()
ie:
Copy code
val one = GlobalScope.async() { A() }
one.join()
val two = GlobalScope.async() { B() }
h
thanks, but i dont necessarily want to wait for A() to be done. I just want to guarantee that
two
will start only after
one
has started
s
Then I would suggest
one
to signal back using a
CompletableDeferred.complete
that you can
join
on then
u
What do you mean by start? When do you consider A started?
You might want to start A undispatched
s
What is your use-case? And when exactly do you consider
{ A() }
to be started? You'd need a third object that would allow your code to coordinate/synchronize the two.
h
You could have
one
start
two
maybe? Since
one
should be in a good position to know exactly when `two`is to be started.
u
Usually in that case you would indeed use
start = CoroutineStart.UNDISPATCHED
, as Uli already said. I don't think you can use LAZY and then start UNDISPATCHED later, though.
h
In the end I just had
one
started
two like @hallvard said