How it works...
In the end, our code is going to display a progress-bar animation for five seconds and then stop it. We are scheduling the `show progress animation`() function to run in the background by invoking it inside a new coroutine instance created by the launch() function. We are storing a handle to a Job instance returned by the launch() function under the job variable.
Next, we are suspending the outer runBlocking() coroutine scope by five seconds with the delay(5000) call. Once the delay() function resumes coroutine execution, we call the cancel() function on the coroutine Job responsible for displaying the progress-bar animation.
Under the hood, inside the `show progress animation`() function, we are running an infinite while ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access