Kotlin Coroutines from theory to practice - Part 3: Coroutines Context

preview_player
Показать описание
Kotlin Coroutines is a concurrency design patter that helps you to deal with asynchronous. The main idea of Kotlin Coroutines is suspend execution. Kotlin Coroutines also allows you select the thread that the function run on and control its life-cycle by using Coroutines Context.
Coroutines Context has 4 main elements: Dispatcher, Job, Coroutines Name and Coroutine Exception Handler.
Dispatcher has 4 types: IO, Main, Default and UnConfined. By using Dispatcher, you can select the thread that Coroutines runs on.
Job is background job. It has a life-cycle. And we usually use it to control the life-cycle of Coroutines. And you also cancel Coroutinew by calling cancle function of Job.
Corutines Name is the name of coroutines. This element just is useful in debugging.
Coroutines Exception Handler provides us a way to deal with the exception that will be thrown when there is any issues while running the Coutines.
All these elements is explained very detail in this video.
Рекомендации по теме