Media
Master Coroutine in 2 Hours: Free Course
In this 2 hour tutorial, you will learn everything you need to know about Coroutines in Kotlin using demos in IntelliJ IDEA and precise presentation.
In this 2 hour tutorial, you will learn everything you need to know about Coroutines in Kotlin using demos in IntelliJ IDEA and precise presentation.
There are 5 chapters in this course.
In chapter 1, get a solid understanding of what are coroutines.
- Explore the ‘suspend’ keyword, compare with threads, delay function, Thread.sleep function and a lot more.
- Basics of coroutine builders: launch, async, and runBlocking.
In chapter 2, dive deeper into Coroutine Builders and explore them in detail.
- Use GlobalScope companion object to launch coroutines.
- Why GlobalScope is discouraged to use?
- Test suspending functions by writing a JUnit test case.
In chapter 3, learn to cancel coroutines and handle exceptions.
- What is a cooperative coroutine?
- How to write cooperative code?
- Explore job.cancel(), and job.cancelAndJoin() functions.
- Use of yield() and delay() suspending functions (suspend modifier).
- Explore what is CoroutineScope.isActive boolean flag.
- Handle CancellationException and TimeoutCancellationException.
- Use withContext(NonCancellable), withTimeout, and withTimeoutOrNull coroutine builders
In chapter 4, compose suspending functions in different ways within a coroutine.
- Explore how code execution in coroutine is sequential by default.
- How to execute suspending functions in a coroutine concurrently?
- Lazily execute async coroutine by using CoroutineStart.LAZY
In chapter 5, learn a few advanced coroutine concepts.
- Understand what is CoroutineScope?
- What is CoroutineContext?
- What is a Dispatcher?
- Role of a dispatcher: to assign a thread to a coroutine.
- Types of Dispatcher: Confined, Unconfined, Default, Main, and IO
- Components of CoroutineContext: Job, Dispatcher, and CoroutineName.
Source code link: https://bit.ly/2QtcUWR
Timestamps:
- 00:00:00 Course Overview
- 00:03:20 Chapter 1: Coroutine Fundamentals
- 00:03:40 Threads vs. Coroutines
- 00:07:25 What are Coroutines?
- 00:08:34 Coroutines Properties
- 00:09:52 Implement Coroutines
- 00:22:15 delay function
- 00:27:38 suspend function
- 00:28:35 runBlocking lambda
- 00:33:31 Custom suspending function
- 00:34:41 Chapter 1: Summary
- 00:36:12 Chapter 2: Coroutine Builders
- 00:36:53 Coroutine Builders
- 00:38:21 Purpose of GlobalScope
- 00:43:26 launch coroutine builder
- 00:50:26 async coroutine builder
- 00:55:18 runBlocking coroutine builder
- 01:00:25 Chapter 2: Summary
- 01:01:53 Chapter 3: Coroutine Cancellation and Exception Handling
- 01:02:31 What is Cooperative Cancellation?
- 01:11:32 yield function
- 01:13:16 isActive flag
- 01:17:48 Handling CancellationException
- 01:20:29 withContext Coroutine Builder
- 01:22:20 Throw Exception with message
- 01:23:43 Timeouts: withTimeout & withTimeoutOrNull
- 01:28:42 Chapter 3: Summary
- 01:30:07 Chapter 4: Composing Suspending Functions
- 01:31:58 Sequential Execution
- 01:36:44 Concurrent Execution
- 01:40:40 Lazy Async Execution
- 01:44:53 Chapter 4: Summary
- 01:45:31 Chapter 5: CoroutineScope, CoroutineContext, and Dispatchers
- 01:46:18 CoroutineScope
- 01:50:15 CoroutineContext (Dispatchers)
- 02:07:06 Thank You!