This course is available as part of the raywenderlich.com Professional subscription. To learn more click here

Kotlin Coroutines: In Depth

Pro

Jan 28 2020 · Video Course (1 hr, 18 mins) · Advanced

Learn how to implement coroutines in a real-world example of an Android application, with structured layers and decoupled dependencies. You'll see how to test coroutines, handle errors, and structure concurrency in a clean and stable way.

4.9/5 14 Ratings

Version

  • Kotlin 1.3, Android 10, Studio 3.5.1

Dive Into Coroutines

Take a tour around asynchronous programming mechanisms in Android, and learn what coroutines are, how they work, and why you should consider using them instead.

1

In this episode, start your first coroutine Job, and see what its lifecycle is.

2

Understand what the CoroutineContext is, and how it influences coroutines.

3

Explore some advanced Job relations and functionality, and how to communicate the lifecycle of coroutines to the rest of the project.

4

Implement Coroutines In Android

Learn the structure and the features of the project you'll be working on, and how to use the best practices of Kotlin Coroutines.

5

Launch the basic Kotlin Coroutine functions, to simplify background work in the project.

6

Learn how to bind your coroutines to the lifecycle of your app's components, such as Activities or Fragments.

7

Learn what context switching means, and how to bridge the gap between asynchronous and synchronous worlds. Dive into the concept of suspendability.

8

Separate business logic from context switching and threading by abstracting away implementation details. Decouple dependencies for context providing to support testing.

9

Debug & Test Coroutines

Handle errors that occur within coroutines with custom error handlers or manual exception catching. Or, instead of working with exceptions, wrap your data with a Result.

10

Apply needed changes to have a clear log of information, about which coroutines are running and in which threads.

11

Learn how to set up the testing environment, so you can easily run and test coroutines using JUnit 4 and Mockito, and verify the functionality of your code.

12

Coroutines With Libraries

Instead of awaiting a Response from Retrofit, use the suspend function approach to expect an entity model directly from the API.

13

Remove async calls and wrappers, and rely on the internal Room logic to fetch data without blocking.

14

Find out how to connect the Android Lifecycle and the CoroutineScope to handle cancellation automatically using ViewModels.

15

Who is this for?

This course is for Android developers who have heard about coroutines, or have tried writing concurrency code using coroutines, but want to learn more about advanced usage in real-world examples. This is also for people who understand coroutines but want to learn the best practices of using coroutines.

It expects you to be familiar with Android Studio, Kotlin, and the basics of using Retrofit and Room in Android. Familiarity with architectural patterns such as the MVP, or MVVM is helpful, but not crucial to this course. Knowledge about Mockito and JUnit4 is required, for the second part of the course.

Covered concepts

  • The theoretical computer science background behind coroutines.
  • Implementing coroutines to replace callbacks.
  • Coroutine Jobs and their lifecycle.
  • CoroutineScope and binding coroutines to lifecycle-aware components.
  • Writing explicit and idiomatic concurrency code.
  • Context switching in coroutines in a clean way, decoupling and keeping implementation details from high-level components.
  • Basic and custom exception handling in coroutines.
  • Wrapping data and exceptions from coroutines to a state-machine result.
  • Logging coroutine threads and information.
  • Testing coroutines using the JUnit framework.
  • Dealing with delays and time logic in coroutine tests.

Contributors

Comments