Challenge: Testing Kotlin Coroutines

Solve a challenge on how to test coroutines.

We'll cover the following

Problem

Write a program to start two coroutines. We need to keep the following points in mind:

  • When we start the first coroutine, no operation will be invoked.
  • When we start the second coroutine, it should immediately invoke all the operations before the first delay on started coroutines.

The first coroutine print operations are:

  • “First coroutine started.”
  • Delay of 2 seconds.
  • “First coroutine ended.”

The second coroutine print operations are:

  • “Second coroutine started.”
  • Delay of 2 seconds.
  • “Second coroutine ended.”

Restriction

The output will be available in the terminal.

Output

Second coroutine started

Get hands-on with 1200+ tech skills courses.