Summary

This chapter contained information that is vital when working with coroutines. Knowing about the different states of a job and how to calculate the current one is important in order to monitor them. Let's recap the topics that were covered in this chapter:

  • Job is used for background tasks that don't return anything.
  • Deferred is used when the background operation returns something that we want to receive.
  • A job can have many states: New, Active, Canceling, Cancelled, and Completed.
  • The isActive, isCancelled, and isCompleted properties can be used to determine the current state of a job.
  • Deferred extends job to add the possibility to return something.
  • The possible states of deferred are the same as that of a job.
  • A job's state can only move forward; it can't be returned to a previous state.
  • A final state is one of the states from which a job can't move.
  • The final states of job are Cancelled and Completed.
  • If deferred is waited on using join(), it's mandatory to validate whether it was cancelled before trying to read its value, to prevent exceptions from being propagated.
  • Always log or display the exceptions in your jobs.

In the next chapter, we will update our application's UI to display the news in an scrollable list. From there, we will move on to an important topic—suspending functions. We will study them in detail, along with their use cases, and, of course, we will integrate them into the RSS reader.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.140.196.244