Shape Shape point chapter-list Group Group Group Group Group Shape Copy 12 Shape Shape Copy 3 Shape Shape dropdown editor editor Combined Shape grid Shape Copy 4 Shape Copy 7 Shape language language Shape megaphone paperback Shape platform noun_419259-2 copy play-icon BS-Question-Rounded-Circle quotes noun_610406 stacked-books-1 stacked-books-2 Group Group Group Group Group Group Group Group Group Path

Kotlin Coroutines by Tutorials

$59.99 5/5 4 reviews · Write a Review
  • Platform Android 10
  • Language Kotlin 1.3
  • Editor AS 3.5

Android is inherently asynchronous and event-driven, with strict requirements as to on which thread certain things can happen.

Learn how to use Kotlin coroutines to solve common Android programming problems using asynchronous programming techniques!

Developer Guide

Intermediate

For Intermediate Developers

The importance of concurrency is discovered quite early on by people who start with Android development. Android is inherently asynchronous and event-driven, with strict requirements as to on which thread certain things can happen.

Add to this the often-cumbersome Java callback interfaces, and you will be trapped in spaghetti code pretty quickly (aptly termed as “Callback Hell”). No matter how many coding patterns you use to avoid that, you will have to encounter the state change across multiple threads in one way or the other.

The only way to create a responsive app is by leaving the UI thread as free as possible, letting all the hard work be done asynchronously by background threads.

Kotlin Coroutines by Tutorials will teach you the techniques you need to solve common programming problems using asynchronous programming.

Table of Contents

Section I: Introduction to Coroutines

1.

What Is Asynchronous Programming? - Updated

In this very first chapter, you’ll learn what asynchronous programming means and why a modern developer should understand it. You’ll see the basics of multithreading like queue and shared memory, and you’ll understand how to solve the "Indentation Hell Problem."

2.

Setting Up Your Build Environments - Updated

Learning through example is one of the most efficient ways to gain more skills. To do this, you need to set up your build environment and learn how to load the starting projects with IntelliJ or Android Studio. This chapter describes all you need to start writing your code.

3.

Getting Started with Coroutines - Updated

This is the chapter where you’ll learn the main concepts about coroutines like builders, scope and context. You’ll see for the first time the Job object and learn how to manage dependencies between coroutines. You’ll understand and write code to manage one of the most important features of asynchronous tasks: cancellations.

4.

Suspending Functions - Updated

To understand how to use coroutines, you need to learn what a suspending function is and how to implement it. In this chapter, you’ll learn all you need to create and use your suspending functions. You’ll also learn how to change your existing functions to use them in a coroutine.

5.

Async/Await - Updated

In multithreading and asynchronous development in Java, you often use Runnable, Callable and Future. With coroutines, you can use Deferred instead. These are objects that you can manage using the async/await functions. In this chapter, you’ll write code to understand when and how to use this pattern most effectively.

6.

Coroutine Context - Updated

his chapter is about one of the most important concepts about coroutines: Coroutine Context. You'll learn what it is and how this is related to the dependencies between different coroutine jobs. You'll also learn how to create your context.

7.

Context Switch & Dispatching - Updated

In this chapter, you'll learn how to run different Jobs into the proper thread. You'll learn how to configure and use the proper thread to display information on the UI or to invoke different services on the network.

8.

Exception Handling - Updated

Using functions with a callback is not difficult only because of the indentation hell problem but also for error and exception handling. In this very important chapter, you’ll learn, with several examples, all the techniques you can use to handle exceptions.

9.

Manage Cancellation - Updated

One of the most important topics to master when you deal with multithreading is a cancellation. Starting a thread is very easy compared to the techniques used to cancel it leaving the system in a consistent state. In this very important chapter, you’ll learn, with several examples, all the techniques you can use to manage cancellations.

Section II: Channels & Flows

10.

Building Sequences & Iterators with Yield - Updated

Sequences are one of the most interesting features of Kotlin because they allow generating values lazily. When you implement a sequence you use the yield function which is a suspending function. In this chapter, you’ll learn how to create sequences and how the yield function can be used to optimize performance.

11.

Channels - Updated

Although experimental, channels are a very important API you can use with coroutines. In this chapter, you’ll create examples to understand what a channel is and how to act as a producer or consumer for it synchronously and asynchronously. You’ll understand how to use multiple channels in the case of multiple senders and receivers. You’ll finally compare channels with Java’s BlockingQueue.

12.

Broadcast Channels - Updated

In this chapter, you’ll write many examples to experiment with using channels with multiple receivers and emitted items need to be shared by all of them.

13.

Producers & Actors - Updated

In this chapter, you’ll learn how coroutines can help implement a producer/consumer pattern using different types of producers and consumers. Another approach to running tasks in the background is to use the actors model. In the second part of this chapter, you’ll learn what an Actor is and how you can use it with coroutines.

14.

Beginning with Coroutine Flow - New

In this chapter, you'll learn what Coroutine Flow is and how to use them in your project.

15.

Testing Coroutines - New

Testing is a fundamental part of the development process and coroutines are not different. In this chapter, you'll learn how to test coroutines using the main testing frameworks.

Section III: Coroutines & Android

16.

Android Concurrency Before Coroutines - Updated

The Android platform allows you to run background tasks in many different ways. In this chapter, you’ll see and implement examples for all of them. You’ll learn what Looper and Handler are and when to use an AsyncTask. You’ll finally see how coroutines can make the code more readable and efficient.

17.

Coroutine on Android - Part 1 - Updated

This chapter covers using Kotlin Coroutines in an Android app, covering working with various context; i.e., UI and background to simplify and manage code sequentially. It will cover converting async callbacks for long-running tasks, such as a database or network access into sequential tasks while also keeping track and handling of the app lifecycle.

18.

Coroutine on Android - Part 2 - Updated

This chapter covers fortifying the use of Kotlin Coroutines in an Android app; i.e., enabling logging, exception handling, debugging and testing of code that uses Kotlin Coroutines. You will also discover the Anko library.

Meet the Team

Average Rating

5 /5

Leave a review for this product

4 reviews

Kotlin Coroutines by Tutorials

Android is inherently asynchronous and event-driven, with strict requirements as to on which thread certain things can happen.

Learn how to use Kotlin coroutines to solve common Android programming problems using asynchronous programming techniques!

Top