Member-only story

Coroutines Masterclass: Chapter-3: coroutines cancellation and exception handling.

SUMIT KUMAR
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(), and job.cancelAndJoin() functions.
  • yield() and delay() suspending functions.
  • CancellationException and TimeoutCancellationException.
  • withContext(NonCancellable), withTimeout, and withTimeoutOrNull 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?🤨

--

--

SUMIT KUMAR
SUMIT KUMAR

Written by SUMIT KUMAR

SDE(Android) || Ex-Ingenium || Modern Mobile Developer📱

Responses (4)