Hello, is it possible to run some code at the exac...
# coroutines
g
Hello, is it possible to run some code at the exact same time from different coroutines in different coroutineScopes?
k
Yes. The two coroutines would have to be running in parallel threads.
j
yeah. don't do
Copy code
coroutineScope{launch{foo()}}
coroutineScope{launch{foo2()}}
And expect concurrency
k
They can expect concurrency just fine. They should not expect parallelism
j
no. the second scope won't get created until the first scope finishes
k
Oh whoops right I thought it was launching into two separate scopes by accident
c
You can never guarantee that two functions will run exactly at the same time. Even if you manage to start them in two threads exactly at the same time, there are more threads than CPU cores, and the JVM, the kernel, and your CPU itself can pause anything anytime they want and delay for however long they want.
g
Yes, you're right 😉 The use case is to update Compose UI Components at the same time, and I did it with a coroutine per each. which is useless because they need to update at the same time anyway So I've changed it and made one Ticker that changes its state on each tick so each component can now
remember(ticker)
and do stuff at the same time. Thank you all for your help!