Kotlin Coroutines: In Depth [FREE]

栏目: IT技术 · 发布时间: 6年前

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.


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

内容算法

内容算法

闫泽华 / 中信出版社 / 2018-4-30 / 58.00元

近两年来,伴随着BAT纷纷涌入自媒体平台,自媒体发展可谓迎来爆发。自媒体平台火爆起来是从今日头条异军突起而引发的。它是一款基于数据挖掘的推荐引擎产品,为用户推荐有价值的、个性化的信息,是国内移动互联网领域成长最快的产品服务之一。推荐引擎也将迎来高速发展,针对推荐引擎的优化技术也将会迎来新的机遇。 本书作者从事推荐引擎相关的内容分发相关工作,在书中对内容推荐系统进行了介绍,书的最后,介绍了自媒......一起来看看 《内容算法》 这本书的介绍吧!

随机密码生成器
随机密码生成器

多种字符组合密码

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具