This is, in effect, "hello, world" in the realm of coroutines. If you run this, you will see one message printed immediately and the other after a short delay.

There are five main elements when working with coroutines:

  1. A CoroutineScope, such as the GlobalScope that is used here

  2. A coroutine builder, such as the launch() function on GlobalScope

  3. Dispatchers, such as Dispatchers.Default and Dispatchers.Main

  4. suspend functions, for marking code that can be suspended safely so other code can run

  5. A CoroutineContext, such as the one created via withContext(), to change which dispatcher should be used for some code

All of these will be explored in upcoming lessons.

You can learn more about this in:
Tags:
Run Edit