What I wonder, though, is how exactly “happens before” is achieved with Kotlin coroutines?

In your case, A is:

val m = mutableMapOf<Int,String>()
m[1] = "one"
yield
() // or other suspending function

And B is:

m[2] = "two" // (2)

So what’s A=>B?

Solutions Architect @Depop, author of “Hands-on Design Patterns with Kotlin” book and “Web Development with Kotlin” course

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store