
The basics of Kotlin coroutines
Description
Book Introduction
This book is written so that anyone can easily understand asynchronous programming, which many developers find difficult, through various visual materials and explanations.
This book is recommended for developers using Kotlin, including Android and Spring, who want to learn asynchronous programming using coroutines from the basics to advanced levels.
This book is recommended for developers using Kotlin, including Android and Spring, who want to learn asynchronous programming using coroutines from the basics to advanced levels.
- You can preview some of the book's contents.
Preview
index
Chapter 1: Limitations of Thread-Based Work and the Emergence of Coroutines
1.1. JVM processes and threads
1.2.
Limitations of Single-Threading and Multi-Threaded Programming
1.2.1.
Limitations of single-threaded applications
1.2.2.
Overcoming the limitations of single-threading through multi-threaded programming
1.3.
Multithreaded programming using threads and thread pools
1.3.1.
How to use the Thread class and its limitations
1.3.2.
Using a thread pool through the Executor framework
1.3.3.
Multithreaded programming and its limitations
1.4.
Limitations of Traditional Multithreaded Programming and Coroutines
1.4.1.
Limitations of existing multi-threaded programming
1.4.2.
How do coroutines overcome thread blocking problems?
1.5.
summation
Chapter 2 Setting up a Coroutine Development Environment
2.1.
Installing and Exploring IntelliJ IDEA
2.1.1.
Installing IntelliJ IDEA 58
2.2.
Create a Kotlin project and explore its screen layout.
2.2.1.
Create a project
2.2.2. Examining the IDE Configuration
2.3.
Running your first coroutine
2.3.1.
Adding the coroutine library
2.3.2.
Running your first coroutine
2.4.
Setting up a coroutine debugging environment
2.4.1.
Print running threads
2.4.2.
Print the name of the running coroutine
2.4.3.
Using launch to run additional coroutines
2.4.4.
Adding a name to a coroutine using CoroutineName
2.5.
summation
Chapter 3 CoroutineDispatcher
3.1.
What is CoroutineDispatcher?
3.1.1.
Examining the behavior of CoroutineDispatcher
3.1.2.
The role of CoroutineDispatcher
3.2.
Limited and Unlimited Dispatchers
3.3.
Creating a restricted dispatcher
3.3.1.
Creating a single-threaded dispatcher
3.3.2.
Creating a multi-threaded dispatcher
3.4.
Running a coroutine using CoroutineDispatcher
3.4.1.
Using CoroutineDispatcher as a parameter of launch
3.4.2.
Running a child coroutine using the parent coroutine's CoroutineDispatcher
3.5.
Predefined CoroutineDispatcher
3.5.1.
Dispatchers.IO
3.5.2.
Dispatchers.Default
3.5.3.
Limiting the use of Dispatchers.Default threads using limitedParallelism
3.5.4.
Dispatchers.IO and Dispatchers.Default4 using a shared thread pool
3.5.5.
Dispatchers.Main
3.6.
summation
Chapter 4: Coroutine Builders and Jobs
4.1.
Sequential processing of coroutines using join
4.1.1.
Problems when sequential processing is not possible
4.1.2.
Sequential processing using the join function
4.2.
Sequential processing of coroutines using joinAll
4.2.1.
joinAll function
4.2.2.
Try using the joinAll function
4.3.
Starting a coroutine late using CoroutineStart.LAZY
4.3.1.
Preparing to look at delayed start
4.3.2.
Starting a coroutine late using CoroutineStart.LAZY
4.4.
Canceling a coroutine
4.4.1.
Canceling a Job Using Cancel
4.4.2.
Sequential processing using cancelAndJoin
4.5.
Confirming cancellation of coroutine
4.5.1.
Cancellation confirmation using delay
4.5.2.
Cancellation confirmation using yield
4.5.3.
Checking for cancellation using CoroutineScope.isActive
4.6.
Coroutine status and Job status variables
4.6.1.
Create a function that prints the status of a job
4.6.2.
Coroutine in creation state
4.6.3.
Coroutine in running state
4.6.4.
Coroutine in execution completed state
4.6.5.
Canceling coroutine
4.6.6.
Cancelled coroutine
4.6.7.
Status Summary
4.7.
summation
Chapter 5 Async and Deferred
5.1.
Receiving the result using async
5.1.1.
Creating a Deferred using async
5.1.2.
Receiving result values using await
5.2.
Deferred is a special type of job
5.3.
Receiving results from multiple coroutines
5.3.1.
Receiving results from multiple coroutines using await
5.3.2.
Receiving the result using awaitAll
5.3.3.
Using awaitAll on collections
5.4.
withContext
5.4.1.
Replacing async-await with withContext
5.4.2.
How withContext works
5.4.3.
Precautions when using withContext
5.5.
summation
Chapter 6 CoroutineContext
6.1.
Components of CoroutineContext
6.2.
Configuring CoroutineContext
6.2.1.
How CoroutineContext Manages Components
6.2.2.
Configuring CoroutineContext
6.2.3.
Overriding the CoroutineContext component
6.2.4.
Combining CoroutineContexts with Multiple Components
6.2.5.
Create a Job and add it to CoroutineContext
6.3.
Accessing the CoroutineContext component
6.3.1.
Keys of CoroutineContext component
6.3.2.
Accessing CoroutineContext components using keys
6.4.
Removing the CoroutineContext component
6.4.1.
Removing elements using minusKey
6.4.2.
Things to note when using the minusKey function
6.5.
summation
Chapter 7 Structured Concurrency
7.1.
Execution environment inheritance
7.1.1.
Inheriting the execution environment of the parent coroutine
7.1.2.
Overwrite the execution environment
7.1.3.
Non-inherited Job
7.1.4.
Job used for structuring
7.2.
Structuring and Task Control of Coroutines
7.2.1.
Propagation of cancellation
7.2.2.
Completion dependency of a parent coroutine on its child coroutine
7.3.
Managing coroutines using CoroutineScope
7.3.1.
Creating a CoroutineScope
7.3.2.
CoroutineScope, which provides an execution environment for coroutines.
7.3.3.
The scope of a coroutine belonging to CoroutineScope
7.3.4.
Canceling CoroutineScope
7.3.5.
Checking CoroutineScope activation status
7.4.
Structuring and Job
7.4.1.
runBlocking and the root Job
7.4.2.
Breaking the Job Structure
7.4.3.
Using Jobs to prevent only some coroutines from being canceled
7.4.4.
Explicitly set the parent of the created Job
7.4.5.
The created job does not automatically complete execution.
7.5.
summation
Chapter 8 Exception Handling
8.1.
Exception propagation in coroutines
8.1.1.
How exceptions propagate in coroutines
8.1.2.
Exception propagation through examples
8.2.
Exception propagation restrictions
8.2.1.
Limiting exception propagation using Job objects
8.2.2.
Limiting exception propagation using the SupervisorJob object
8.2.3.
Limiting exception propagation using supervisorScope
8.3.
Exception handling using CoroutineExceptionHandler
8.3.1.
Create CoroutineExceptionHandler
8.3.2.
Use CoroutineExceptionHandler
8.3.3.
CoroutineExceptionHandler, which only handles unhandled exceptions
8.3.4.
Make CoroutineExceptionHandler handle exceptions
8.3.5.
CoroutineExceptionHandler does not limit exception propagation.
8.4.
Exception handling using try catch statements
8.4.1.
Handling coroutine exceptions using try catch statements
8.4.2.
The try catch statement for the coroutine builder function does not catch the coroutine's exceptions.
8.5.
async exception handling
8.5.1.
async exception exposure
8.5.2.
async exception propagation
8.6.
Non-propagated exceptions
8.6.1.
CancellationException not propagated
8.6.2.
JobCancellationException used when canceling a coroutine
8.6.3.
Limiting a coroutine's execution time using withTimeOut
8.7.
summation
Chapter 9 Suspend Functions
9.1.
Suspending functions and coroutines
9.1.1.
What is a suspend function?
9.1.2.
Suspending functions are not coroutines
9.1.3.
Running a suspending function in a separate coroutine
9.2.
Using the suspend function
9.2.1.
Callable points of the suspend function
9.2.2.
Running a coroutine from a suspending function
9.3.
summation
Chapter 10: Understanding Coroutines
10.1.
Subroutines and Coroutines
10.1.1.
Routines and subroutines
10.1.2.
Difference between subroutines and coroutines
10.2.
Thread yielding in coroutines
10.2.1.
Understanding thread yielding through the delay suspend function
10.2.2.
Learn more about how join and await work.
10.2.3.
Call the yield function to yield the thread
10.3.
Coroutine execution thread
10.3.1.
The execution thread of a coroutine is not fixed.
10.3.2.
If you don't yield the thread, the execution thread won't change.
10.4.
summation
Chapter 11: Coroutines in Detail
11.1.
Problems with coroutines using shared state and data synchronization
11.1.1.
Problems with using mutable variables
11.1.2. How the JVM's memory space is connected to the hardware memory structure.
11.1.3.
Memory visibility issues and solutions for shared state
11.1.4.
Race Condition Problems and Solutions for Shared State
11.2.
Explore the various options of CoroutineStart
11.2.1.
CoroutineStart.DEFAULT
11.2.2.
CoroutineStart.ATOMIC
11.2.3.
CoroutineStart.UNDISPATCHED
11.3.
Unlimited dispatcher
11.3.1.
What is Unlimited Dispatcher?
11.3.2.
Unlimited Dispatcher Features
11.4.
How Coroutines Work and Continuation
11.4.1.
Continuation Passing Style
11.4.2.
Understanding Continuation through Suspending and Resuming Coroutines
11.4.3.
Resuming a coroutine by receiving results from another task
11.5.
summation
Chapter 12 Coroutine Unit Testing
12.1.
Unit Testing Basics
12.1.1.
What is a unit test?
12.1.2.
Setting up a test environment
12.1.3.
Creating and running a simple test
12.1.4.
Setting up a test environment using the @BeforeEach annotation
12.1.5.
Testing Dependent Objects Using Test Doubles
12.2.
Getting Started with Coroutine Unit Testing
12.2.1.
Writing Your First Coroutine Test
12.2.2.
Limitations of testing using runBlocking
12.3.
Coroutine testing library
12.3.1.
Setting up coroutine test library dependencies
12.3.2.
Running tests in virtual time using TestCoroutineScheduler
12.3.3.
StandardTestDispatcher with TestCoroutineScheduler
12.3.4.
Running tests in virtual time using TestScope
12.3.5.
Creating tests using runTest
12.4.
Creating a coroutine unit test
12.4.1.
Preparing Code for Coroutine Unit Testing
12.4.2.
Writing Tests for the FollowerSearcher Class
12.5.
Deepening Coroutine Testing
12.5.1.
Tests on objects that execute new coroutines inside functions
12.5.2.
Creating tests using backgroundScope
12.6.
summation
1.1. JVM processes and threads
1.2.
Limitations of Single-Threading and Multi-Threaded Programming
1.2.1.
Limitations of single-threaded applications
1.2.2.
Overcoming the limitations of single-threading through multi-threaded programming
1.3.
Multithreaded programming using threads and thread pools
1.3.1.
How to use the Thread class and its limitations
1.3.2.
Using a thread pool through the Executor framework
1.3.3.
Multithreaded programming and its limitations
1.4.
Limitations of Traditional Multithreaded Programming and Coroutines
1.4.1.
Limitations of existing multi-threaded programming
1.4.2.
How do coroutines overcome thread blocking problems?
1.5.
summation
Chapter 2 Setting up a Coroutine Development Environment
2.1.
Installing and Exploring IntelliJ IDEA
2.1.1.
Installing IntelliJ IDEA 58
2.2.
Create a Kotlin project and explore its screen layout.
2.2.1.
Create a project
2.2.2. Examining the IDE Configuration
2.3.
Running your first coroutine
2.3.1.
Adding the coroutine library
2.3.2.
Running your first coroutine
2.4.
Setting up a coroutine debugging environment
2.4.1.
Print running threads
2.4.2.
Print the name of the running coroutine
2.4.3.
Using launch to run additional coroutines
2.4.4.
Adding a name to a coroutine using CoroutineName
2.5.
summation
Chapter 3 CoroutineDispatcher
3.1.
What is CoroutineDispatcher?
3.1.1.
Examining the behavior of CoroutineDispatcher
3.1.2.
The role of CoroutineDispatcher
3.2.
Limited and Unlimited Dispatchers
3.3.
Creating a restricted dispatcher
3.3.1.
Creating a single-threaded dispatcher
3.3.2.
Creating a multi-threaded dispatcher
3.4.
Running a coroutine using CoroutineDispatcher
3.4.1.
Using CoroutineDispatcher as a parameter of launch
3.4.2.
Running a child coroutine using the parent coroutine's CoroutineDispatcher
3.5.
Predefined CoroutineDispatcher
3.5.1.
Dispatchers.IO
3.5.2.
Dispatchers.Default
3.5.3.
Limiting the use of Dispatchers.Default threads using limitedParallelism
3.5.4.
Dispatchers.IO and Dispatchers.Default4 using a shared thread pool
3.5.5.
Dispatchers.Main
3.6.
summation
Chapter 4: Coroutine Builders and Jobs
4.1.
Sequential processing of coroutines using join
4.1.1.
Problems when sequential processing is not possible
4.1.2.
Sequential processing using the join function
4.2.
Sequential processing of coroutines using joinAll
4.2.1.
joinAll function
4.2.2.
Try using the joinAll function
4.3.
Starting a coroutine late using CoroutineStart.LAZY
4.3.1.
Preparing to look at delayed start
4.3.2.
Starting a coroutine late using CoroutineStart.LAZY
4.4.
Canceling a coroutine
4.4.1.
Canceling a Job Using Cancel
4.4.2.
Sequential processing using cancelAndJoin
4.5.
Confirming cancellation of coroutine
4.5.1.
Cancellation confirmation using delay
4.5.2.
Cancellation confirmation using yield
4.5.3.
Checking for cancellation using CoroutineScope.isActive
4.6.
Coroutine status and Job status variables
4.6.1.
Create a function that prints the status of a job
4.6.2.
Coroutine in creation state
4.6.3.
Coroutine in running state
4.6.4.
Coroutine in execution completed state
4.6.5.
Canceling coroutine
4.6.6.
Cancelled coroutine
4.6.7.
Status Summary
4.7.
summation
Chapter 5 Async and Deferred
5.1.
Receiving the result using async
5.1.1.
Creating a Deferred using async
5.1.2.
Receiving result values using await
5.2.
Deferred is a special type of job
5.3.
Receiving results from multiple coroutines
5.3.1.
Receiving results from multiple coroutines using await
5.3.2.
Receiving the result using awaitAll
5.3.3.
Using awaitAll on collections
5.4.
withContext
5.4.1.
Replacing async-await with withContext
5.4.2.
How withContext works
5.4.3.
Precautions when using withContext
5.5.
summation
Chapter 6 CoroutineContext
6.1.
Components of CoroutineContext
6.2.
Configuring CoroutineContext
6.2.1.
How CoroutineContext Manages Components
6.2.2.
Configuring CoroutineContext
6.2.3.
Overriding the CoroutineContext component
6.2.4.
Combining CoroutineContexts with Multiple Components
6.2.5.
Create a Job and add it to CoroutineContext
6.3.
Accessing the CoroutineContext component
6.3.1.
Keys of CoroutineContext component
6.3.2.
Accessing CoroutineContext components using keys
6.4.
Removing the CoroutineContext component
6.4.1.
Removing elements using minusKey
6.4.2.
Things to note when using the minusKey function
6.5.
summation
Chapter 7 Structured Concurrency
7.1.
Execution environment inheritance
7.1.1.
Inheriting the execution environment of the parent coroutine
7.1.2.
Overwrite the execution environment
7.1.3.
Non-inherited Job
7.1.4.
Job used for structuring
7.2.
Structuring and Task Control of Coroutines
7.2.1.
Propagation of cancellation
7.2.2.
Completion dependency of a parent coroutine on its child coroutine
7.3.
Managing coroutines using CoroutineScope
7.3.1.
Creating a CoroutineScope
7.3.2.
CoroutineScope, which provides an execution environment for coroutines.
7.3.3.
The scope of a coroutine belonging to CoroutineScope
7.3.4.
Canceling CoroutineScope
7.3.5.
Checking CoroutineScope activation status
7.4.
Structuring and Job
7.4.1.
runBlocking and the root Job
7.4.2.
Breaking the Job Structure
7.4.3.
Using Jobs to prevent only some coroutines from being canceled
7.4.4.
Explicitly set the parent of the created Job
7.4.5.
The created job does not automatically complete execution.
7.5.
summation
Chapter 8 Exception Handling
8.1.
Exception propagation in coroutines
8.1.1.
How exceptions propagate in coroutines
8.1.2.
Exception propagation through examples
8.2.
Exception propagation restrictions
8.2.1.
Limiting exception propagation using Job objects
8.2.2.
Limiting exception propagation using the SupervisorJob object
8.2.3.
Limiting exception propagation using supervisorScope
8.3.
Exception handling using CoroutineExceptionHandler
8.3.1.
Create CoroutineExceptionHandler
8.3.2.
Use CoroutineExceptionHandler
8.3.3.
CoroutineExceptionHandler, which only handles unhandled exceptions
8.3.4.
Make CoroutineExceptionHandler handle exceptions
8.3.5.
CoroutineExceptionHandler does not limit exception propagation.
8.4.
Exception handling using try catch statements
8.4.1.
Handling coroutine exceptions using try catch statements
8.4.2.
The try catch statement for the coroutine builder function does not catch the coroutine's exceptions.
8.5.
async exception handling
8.5.1.
async exception exposure
8.5.2.
async exception propagation
8.6.
Non-propagated exceptions
8.6.1.
CancellationException not propagated
8.6.2.
JobCancellationException used when canceling a coroutine
8.6.3.
Limiting a coroutine's execution time using withTimeOut
8.7.
summation
Chapter 9 Suspend Functions
9.1.
Suspending functions and coroutines
9.1.1.
What is a suspend function?
9.1.2.
Suspending functions are not coroutines
9.1.3.
Running a suspending function in a separate coroutine
9.2.
Using the suspend function
9.2.1.
Callable points of the suspend function
9.2.2.
Running a coroutine from a suspending function
9.3.
summation
Chapter 10: Understanding Coroutines
10.1.
Subroutines and Coroutines
10.1.1.
Routines and subroutines
10.1.2.
Difference between subroutines and coroutines
10.2.
Thread yielding in coroutines
10.2.1.
Understanding thread yielding through the delay suspend function
10.2.2.
Learn more about how join and await work.
10.2.3.
Call the yield function to yield the thread
10.3.
Coroutine execution thread
10.3.1.
The execution thread of a coroutine is not fixed.
10.3.2.
If you don't yield the thread, the execution thread won't change.
10.4.
summation
Chapter 11: Coroutines in Detail
11.1.
Problems with coroutines using shared state and data synchronization
11.1.1.
Problems with using mutable variables
11.1.2. How the JVM's memory space is connected to the hardware memory structure.
11.1.3.
Memory visibility issues and solutions for shared state
11.1.4.
Race Condition Problems and Solutions for Shared State
11.2.
Explore the various options of CoroutineStart
11.2.1.
CoroutineStart.DEFAULT
11.2.2.
CoroutineStart.ATOMIC
11.2.3.
CoroutineStart.UNDISPATCHED
11.3.
Unlimited dispatcher
11.3.1.
What is Unlimited Dispatcher?
11.3.2.
Unlimited Dispatcher Features
11.4.
How Coroutines Work and Continuation
11.4.1.
Continuation Passing Style
11.4.2.
Understanding Continuation through Suspending and Resuming Coroutines
11.4.3.
Resuming a coroutine by receiving results from another task
11.5.
summation
Chapter 12 Coroutine Unit Testing
12.1.
Unit Testing Basics
12.1.1.
What is a unit test?
12.1.2.
Setting up a test environment
12.1.3.
Creating and running a simple test
12.1.4.
Setting up a test environment using the @BeforeEach annotation
12.1.5.
Testing Dependent Objects Using Test Doubles
12.2.
Getting Started with Coroutine Unit Testing
12.2.1.
Writing Your First Coroutine Test
12.2.2.
Limitations of testing using runBlocking
12.3.
Coroutine testing library
12.3.1.
Setting up coroutine test library dependencies
12.3.2.
Running tests in virtual time using TestCoroutineScheduler
12.3.3.
StandardTestDispatcher with TestCoroutineScheduler
12.3.4.
Running tests in virtual time using TestScope
12.3.5.
Creating tests using runTest
12.4.
Creating a coroutine unit test
12.4.1.
Preparing Code for Coroutine Unit Testing
12.4.2.
Writing Tests for the FollowerSearcher Class
12.5.
Deepening Coroutine Testing
12.5.1.
Tests on objects that execute new coroutines inside functions
12.5.2.
Creating tests using backgroundScope
12.6.
summation
Detailed image

Publisher's Review
What this book covers
- It explains asynchronous programming using coroutines so that even beginner developers can easily understand it through rich visual materials.
- Explains the limitations of multi-threaded programming before coroutines and how coroutines overcome those limitations.
- Explains how to utilize the various components that make up CoroutineContext.
- Learn about structured concurrency and exception handling methods of coroutines and explain how to make asynchronous programming stable.
- Provides materials for an in-depth understanding of how coroutines work.
- Explains from basic to advanced how to write coroutine unit tests.
Target audience for this book
- Developers who want to build a solid foundation of knowledge about Kotlin coroutines from the basics to the core.
- Developers who want to grow technically by deeply understanding the various functions of coroutines.
- Developers who want to learn how to make asynchronous programming more stable by understanding the structured concurrency and exception handling of coroutines.
- Developers who want to understand how coroutines work
- Developers who want to learn how to write coroutine unit tests
Structure of this book
Chapter 1 covers processes and threads in the JVM.
We will explore how traditional multi-threaded programming has changed and how coroutines overcome the limitations of traditional multi-threaded programming.
Chapter 2 covers how to set up a coroutine development environment using IntelliJ IDEA.
After setting up the development environment, we'll run our first coroutine and learn how to determine which thread the coroutine is running on.
Chapter 3 covers CoroutineDispatcher.
Explains how to create a bounded dispatcher and how to execute a coroutine using the bounded dispatcher.
The coroutine library provides predefined CoroutineDispatchers for your convenience, so let's take a look at what types of predefined CoroutineDispatchers there are and when to use them.
Chapter 4 covers the coroutine builder function launch and the Job object returned when launch is called.
Since coroutines can be suspended, sequential processing between tasks is very important.
We will learn how to use the join function of the Job object to sequentially process coroutines, and how to manipulate the state of coroutines and check the state value through the Job object.
Chapter 5 explains async coroutine builders.
We'll learn how to use async and await to return values from coroutines, and how to use withContext to change the thread on which a coroutine is running.
In Chapter 6, we will learn about CoroutineContext.
Understand that Job, CoroutineDispatcher, and CoroutineName are components of CoroutineContext, and see how to combine or separate components of CoroutineContext.
Chapter 7 explores how structured concurrency is used to safely use coroutines, focusing on the relationship between parent and child coroutines.
Afterwards, we will learn about CoroutineScope, which plays an important role in structuring, and see that Job is at the center of structuring.
Chapter 8 covers exception handling.
We will learn how exceptions are propagated when they occur in a coroutine and confirm that exception propagation occurs due to structured concurrency.
And we'll cover how to use supervisorScope or SupervisorJob to limit the scope to which exceptions can propagate.
Additionally, it explains how to handle propagated exceptions using try catch statements or Coroutine ExceptionHandler.
Chapter 9 covers suspend functions.
Understand that suspending functions are reusable blocks of code and learn what to be careful of when using suspending functions.
Afterwards, we will look at where we can call a suspending function, and how to create a CoroutineScope inside a suspending function without breaking its structure, and run a new child coroutine.
Chapter 10 builds on the previous chapters by covering topics that deepen your understanding of coroutines.
We'll explore the difference between subroutines and coroutines, why yielding threads is important for coroutines to work cooperatively, and what happens when a coroutine is suspended and then resumed.
Chapter 11 explores advanced topics in coroutines.
This article explains data synchronization issues when there are multiple coroutines using shared state in a multi-threaded environment, how to change the execution method of a coroutine using the CoroutineStart option, how the unbounded dispatcher works, and how coroutine suspension and resumption occur.
Chapter 12 covers coroutine unit testing.
Learn how to use the coroutine test library and how to best conduct coroutine unit tests.
Author's Note
As developers create programs, they encounter numerous situations that require asynchronous programming.
In the process, you will overcome numerous difficulties and find solutions for each situation, grow, and become familiar with asynchronous programming.
Asynchronous programming is essential for creating high-performance programs, so understanding asynchronous programming is essential to becoming a competent developer.
However, there are not many learning materials about asynchronous programming.
Additionally, most of these learning materials are written for developers with a certain level of skill, making them difficult for developers who are just starting out to understand.
Kotlin coroutines are no exception.
Coroutines are an asynchronous solution that combines performance, safety, and readability, and it is clear that they will become the standard for asynchronous programming in Kotlin for a long time to come.
Accordingly, many developers have started using coroutines in their work, but there is still a lack of learning materials, and most of them are difficult to understand, especially for beginner developers.
I have tried several things to make coroutines more accessible to developers.
I also posted a series of articles on my technical blog, compiling English books, lectures, and official documentation, and translated the official Coroutine technical documentation into Korean and distributed it on the web.
Although the attempts were well-received, there were limitations to systematically handling coroutines.
Then, I started writing with the thought that I could convey coroutines more systematically through a book.
This book will cover coroutines systematically.
It covers the characteristics of traditional multi-threaded programming, how coroutines overcome the limitations of traditional multi-threaded programming, what the components of coroutines are and how to use them, etc.
This book will help you understand not only how to use coroutines but also what they are trying to solve.
And I've structured it so that you can understand all of this if you only know the Kotlin language.
I hope that this book will help many developers gain a deeper understanding of coroutines.
- It explains asynchronous programming using coroutines so that even beginner developers can easily understand it through rich visual materials.
- Explains the limitations of multi-threaded programming before coroutines and how coroutines overcome those limitations.
- Explains how to utilize the various components that make up CoroutineContext.
- Learn about structured concurrency and exception handling methods of coroutines and explain how to make asynchronous programming stable.
- Provides materials for an in-depth understanding of how coroutines work.
- Explains from basic to advanced how to write coroutine unit tests.
Target audience for this book
- Developers who want to build a solid foundation of knowledge about Kotlin coroutines from the basics to the core.
- Developers who want to grow technically by deeply understanding the various functions of coroutines.
- Developers who want to learn how to make asynchronous programming more stable by understanding the structured concurrency and exception handling of coroutines.
- Developers who want to understand how coroutines work
- Developers who want to learn how to write coroutine unit tests
Structure of this book
Chapter 1 covers processes and threads in the JVM.
We will explore how traditional multi-threaded programming has changed and how coroutines overcome the limitations of traditional multi-threaded programming.
Chapter 2 covers how to set up a coroutine development environment using IntelliJ IDEA.
After setting up the development environment, we'll run our first coroutine and learn how to determine which thread the coroutine is running on.
Chapter 3 covers CoroutineDispatcher.
Explains how to create a bounded dispatcher and how to execute a coroutine using the bounded dispatcher.
The coroutine library provides predefined CoroutineDispatchers for your convenience, so let's take a look at what types of predefined CoroutineDispatchers there are and when to use them.
Chapter 4 covers the coroutine builder function launch and the Job object returned when launch is called.
Since coroutines can be suspended, sequential processing between tasks is very important.
We will learn how to use the join function of the Job object to sequentially process coroutines, and how to manipulate the state of coroutines and check the state value through the Job object.
Chapter 5 explains async coroutine builders.
We'll learn how to use async and await to return values from coroutines, and how to use withContext to change the thread on which a coroutine is running.
In Chapter 6, we will learn about CoroutineContext.
Understand that Job, CoroutineDispatcher, and CoroutineName are components of CoroutineContext, and see how to combine or separate components of CoroutineContext.
Chapter 7 explores how structured concurrency is used to safely use coroutines, focusing on the relationship between parent and child coroutines.
Afterwards, we will learn about CoroutineScope, which plays an important role in structuring, and see that Job is at the center of structuring.
Chapter 8 covers exception handling.
We will learn how exceptions are propagated when they occur in a coroutine and confirm that exception propagation occurs due to structured concurrency.
And we'll cover how to use supervisorScope or SupervisorJob to limit the scope to which exceptions can propagate.
Additionally, it explains how to handle propagated exceptions using try catch statements or Coroutine ExceptionHandler.
Chapter 9 covers suspend functions.
Understand that suspending functions are reusable blocks of code and learn what to be careful of when using suspending functions.
Afterwards, we will look at where we can call a suspending function, and how to create a CoroutineScope inside a suspending function without breaking its structure, and run a new child coroutine.
Chapter 10 builds on the previous chapters by covering topics that deepen your understanding of coroutines.
We'll explore the difference between subroutines and coroutines, why yielding threads is important for coroutines to work cooperatively, and what happens when a coroutine is suspended and then resumed.
Chapter 11 explores advanced topics in coroutines.
This article explains data synchronization issues when there are multiple coroutines using shared state in a multi-threaded environment, how to change the execution method of a coroutine using the CoroutineStart option, how the unbounded dispatcher works, and how coroutine suspension and resumption occur.
Chapter 12 covers coroutine unit testing.
Learn how to use the coroutine test library and how to best conduct coroutine unit tests.
Author's Note
As developers create programs, they encounter numerous situations that require asynchronous programming.
In the process, you will overcome numerous difficulties and find solutions for each situation, grow, and become familiar with asynchronous programming.
Asynchronous programming is essential for creating high-performance programs, so understanding asynchronous programming is essential to becoming a competent developer.
However, there are not many learning materials about asynchronous programming.
Additionally, most of these learning materials are written for developers with a certain level of skill, making them difficult for developers who are just starting out to understand.
Kotlin coroutines are no exception.
Coroutines are an asynchronous solution that combines performance, safety, and readability, and it is clear that they will become the standard for asynchronous programming in Kotlin for a long time to come.
Accordingly, many developers have started using coroutines in their work, but there is still a lack of learning materials, and most of them are difficult to understand, especially for beginner developers.
I have tried several things to make coroutines more accessible to developers.
I also posted a series of articles on my technical blog, compiling English books, lectures, and official documentation, and translated the official Coroutine technical documentation into Korean and distributed it on the web.
Although the attempts were well-received, there were limitations to systematically handling coroutines.
Then, I started writing with the thought that I could convey coroutines more systematically through a book.
This book will cover coroutines systematically.
It covers the characteristics of traditional multi-threaded programming, how coroutines overcome the limitations of traditional multi-threaded programming, what the components of coroutines are and how to use them, etc.
This book will help you understand not only how to use coroutines but also what they are trying to solve.
And I've structured it so that you can understand all of this if you only know the Kotlin language.
I hope that this book will help many developers gain a deeper understanding of coroutines.
GOODS SPECIFICS
- Date of issue: February 29, 2024
- Page count, weight, size: 452 pages | 188*235*21mm
- ISBN13: 9791161758251
- ISBN10: 1161758259
You may also like
카테고리
korean
korean