Could I get some coroutine help, please? (sort of ...
# advent-of-code
e
Could I get some coroutine help, please? (sort of spoilers for part 2?)
I'm trying to execute the same function three times, concurrently. But it's doing it sequentially.
Copy code
override fun solvePartTwo(): Long = runBlocking {
    val xPeriod = async { findPeriod(Point3::x) }
    val yPeriod = async { findPeriod(Point3::y) }
    val zPeriod = async { findPeriod(Point3::z) }
    println("Post launch")
    lcm(xPeriod.await(), yPeriod.await(), zPeriod.await())
}
and this it the output from logs in the
findPeriod
function (at entry and before exit)
Copy code
property x started
property x done
property y started
property y done
property z started
property z done
Would expect it to start at the same time for all of them...
k
runBlocking(Dispatcher.Default)
iirc
e
Ah, thank you! Still very new to coroutines, only started learning them to solve Day 7. 🙂
Funny thing is, takes pretty much the same time to complete. Not too surprising, just wanted to try it out.
m
that's probably because looping through the input and checking for all of the values where you haven't found a loop for yet is the same complexity as looping them parallel individually, because they both take as long as the longest period I presume?
e
Yeah, that's what I figured.