Member-only story
Coroutines Masterclass: Chapter-3: coroutines cancellation and exception handling.
10 min readAug 20, 2023
Welcome to the comprehensive guide on Kotlin Coroutines! In this article series, I will take you on a captivating journey, starting from the fundamentals and gradually delving into advanced concepts. In this article we will talk about cancellation of coroutine. So, grab your favorite cup of coffee, get comfortable, and let’s deep dive into the world of Coroutines.
TOPICS COVERED IN THIS CHAPTER
- Why to cancel a coroutine, what is the reason?
- What is a cooperative coroutine?
- How to write a cooperative code?
job.cancel()
, andjob.cancelAndJoin()
functions.yield()
anddelay()
suspending functions.- CancellationException and TimeoutCancellationException.
withContext(NonCancellable)
,withTimeout
, andwithTimeoutOrNull
coroutine builders- summary
Need of cancellation
Ninja: Coroutines are cheap in terms of resource usage. Why should we cancel them, Master? Will it have any impact, or is cancellation primarily for releasing held resources?🤨