Challenge: Practice a Suspending Function Using Flow

Solve a challenge about the use of flows.

We'll cover the following

Problem

Write a program where you will try to complete the code by starting a coroutine. The coroutine will keep processing three times with a delay of 0.1 seconds, and when the coroutines end, it will print the name of users with a delay of 1 second. You have to make a suspending function named getFlow using Flow, and this function will print the user’s count.

Restriction

The output will be available in the terminal.

Output

The output will be as follows; here, we will see a delay of 0.1 seconds before every coroutine processing statement and 1 second of delay after every user statement. After all the processing and before printing the user, there will be a delay of 0.7 seconds (1(30.1)=0.7)(1-(3*0.1)=0.7).

Coroutine Processing
Coroutine Processing
Coroutine Processing
User0
User1
User2

Get hands-on with 1200+ tech skills courses.