16

Kotlin Coroutines: In Depth [FREE]

 4 years ago
source link: https://www.raywenderlich.com/5443783-kotlin-coroutines-in-depth
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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.

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

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

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

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.

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

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

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

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

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.

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

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.

Coroutines With Libraries

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

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

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


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK