# suspend function

A Kotlin function or functional type marked with the suspend modifier, enabling use as a suspend function within a suspend context.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## The Ghost Work Left Behind by Cancelled Coroutines

DevFeed: [The Ghost Work Left Behind by Cancelled Coroutines](<https://devfeed.tech/articles/the-ghost-work-left-behind-by-cancelled-coroutines-89749.md>)

Original publisher: [Read original article](<https://proandroiddev.com/the-ghost-work-left-behind-by-cancelled-coroutines-a892bd467a6b?source=rss----c72404660798---4>)

Author: Rohan Maity | RotBolt

Published: 2026-10-18T19:56:04Z

Content type: article

Language: en

Sources: [ProAndroidDev](<https://devfeed.tech/sources/proandroiddev-medium.md>)

Topics: [cancellation](<https://devfeed.tech/topics/cancellation.md>), [Coroutines](<https://devfeed.tech/topics/coroutines.md>), [Exception handling](<https://devfeed.tech/topics/exception-handling.md>), [Structured concurrency](<https://devfeed.tech/topics/structured-concurrency.md>), [suspend function](<https://devfeed.tech/topics/suspend-function.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [bluetooth](<https://devfeed.tech/tags/bluetooth.md>), [bridges](<https://devfeed.tech/tags/bridges.md>), [cancellations](<https://devfeed.tech/tags/cancellations.md>), [coroutine](<https://devfeed.tech/tags/coroutine.md>), [coroutines](<https://devfeed.tech/tags/coroutines.md>), [coroutinescope](<https://devfeed.tech/tags/coroutinescope.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-coroutines](<https://devfeed.tech/tags/kotlin-coroutines.md>), [lifecycle](<https://devfeed.tech/tags/lifecycle.md>), [telemetry](<https://devfeed.tech/tags/telemetry.md>)

### AI overview

Kotlin coroutine cancellation is cooperative, so failures occur when code catches CancellationException as an ordinary error, callback bridges fail to cancel underlying requests, blocking calls ignore cancellation, or work runs in scopes without a clear owner. The excerpt links these gaps to misleading error logs and empty results, hanging or stale workflows, wasted IO capacity, Bluetooth work surviving disconnects, and saves lost during logout. It recommends rethrowing cancellation, using cancellable bridges that cancel their requests, preferring suspend APIs (or runInterruptible for interruptible JVM calls), assigning scopes to lifecycle owners, and sequencing critical saves and logout in one coroutine. It also distinguishes timeout-as-error from expected timeout, and notes that a Mutex serializes sends without guaranteeing callback arrival order. The review questions suggest where runtime tracing may help; static review cannot prove that a pattern caused an incident.

### Source excerpt

Lessons from a production Android codebase Cancellation in Kotlin Coroutines looks simple: cancel the Job, and the coroutine stops. In production, it is rarely that clean. Cancellation is cooperative. Every suspend function, exception handler, callback bridge and child scope must carry the signal. Break one boundary, and work may continue after its owner is gone. We saw the result in production: false error logs, empty results, stale Bluetooth work and a final save lost during logout. Nothing crashed. The app simply continued with the wrong state. Cancellation is cooperative Kotlin uses CancellationException to stop a coroutine. Functions such as delay and await check the Job and throw when it is cancelled. val job = scope.launch { delay(5_000) updateState() } job.cancel() Here, delay observes cancellation, so updateState is not called. Regular Kotlin code does not check automatically. It keeps running until the next cancellation point. When cancellation becomes a failure return try { repository.fetchNotifications() } catch (error: Exception) { logger.error("Failed to load notifications", error) emptyList() } If the user leaves the screen, viewModelScope is cancelled and fetchNotifications throws CancellationException. The broad catch records a normal lifecycle event as a failure. It also returns emptyList, so the caller cannot distinguish cancellation from a successful query with no data. runCatching has the same problem because it also catches CancellationException. Rethrow cancellation before handling other failures. catch (error: CancellationException) { throw error } catch (error: Exception) { logger.error("Failed to load notifications", error) emptyList() } In production, normal navigation becomes error telemetry. Empty values can appear as missing documents, notifications or time cards. Support sees missing data while the app reports a completed request. Callback bridges can outlive the caller suspend fun loadMessages() = suspendCoroutine { continuation -> ch

## Part 1: Kotlin Flows -- The Air Compressor of Android (Fundamentals & Cold Streams)

DevFeed: [Part 1: Kotlin Flows -- The Air Compressor of Android (Fundamentals & Cold Streams)](<https://devfeed.tech/articles/part-1-kotlin-flows-the-air-compressor-of-android-fundamentals-cold-streams-88051.md>)

Original publisher: [Read original article](<https://proandroiddev.com/part-1-kotlin-flows-the-air-compressor-of-android-fundamentals-cold-streams-7ae94471c1d7?source=rss----c72404660798---4>)

Author: Sandeep Kella

Published: 2026-10-15T16:34:19Z

Content type: tutorial

Language: en

Sources: [ProAndroidDev](<https://devfeed.tech/sources/proandroiddev-medium.md>)

Topics: [Coroutines](<https://devfeed.tech/topics/coroutines.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Android](<https://devfeed.tech/topics/android.md>), [coroutines-flow](<https://devfeed.tech/topics/coroutines-flow.md>), [suspend function](<https://devfeed.tech/topics/suspend-function.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [backpressure](<https://devfeed.tech/tags/backpressure.md>), [coroutine](<https://devfeed.tech/tags/coroutine.md>), [database](<https://devfeed.tech/tags/database.md>), [delay](<https://devfeed.tech/tags/delay.md>), [flow](<https://devfeed.tech/tags/flow.md>), [generate](<https://devfeed.tech/tags/generate.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-flow](<https://devfeed.tech/tags/kotlin-flow.md>), [network](<https://devfeed.tech/tags/network.md>), [stream](<https://devfeed.tech/tags/stream.md>), [streams](<https://devfeed.tech/tags/streams.md>), [timer](<https://devfeed.tech/tags/timer.md>), [tool](<https://devfeed.tech/tags/tool.md>)

### AI overview

This tutorial introduces Kotlin Flow through an air-compressor analogy, explaining cold streams, collection, operators, cancellation, and backpressure. It also compares Flow with lists, LiveData, and RxJava, and discusses coroutine context and flowOn.

### Source excerpt

Hey! So you want to learn Kotlin Flows? Grab a seat. I know the official documentation can sometimes feel like reading a microwave manual, but I promise you, once you get the mental model right, Flows are going to be your best friend. Forget about the code for a second. Let's talk about air. The Breakdown: The Air Compressor Analogy Imagine you are painting a car using an Air Compressor and a Spray Gun. The Producer (The Compressor): This is where the air is generated. In Kotlin, this is your database, your network call, or a timer. The Flow (The Hose): This is the pipe connecting the compressor to your tool. The Operators (Valves & Filters): Maybe you have a moisture filter on the hose, or a pressure regulator. It modifies the air before it reaches you. The Consumer / Collector (The Spray Gun): This is your Android UI. Here is the most important concept to understand about a standard Kotlin Flow: It is a COLD stream. What does "Cold" mean? Imagine your air compressor is completely turned off and silent. It will not generate a single ounce of air until you pull the trigger on the spray gun. The moment you pull the trigger (in Kotlin, we call this .collect()), the compressor kicks on, air pushes through the filters, and paint comes out. When you let go of the trigger (cancel the coroutine), the whole system shuts down instantly. Diagrammatic Mental Model: Plaintext [Air Compressor] ---> (Pressure Valve) ---> (Moisture Filter) ---> [Spray Gun] (Producer) (Operator: map) (Operator: filter) (Collector) Status: DEAD SILENT until someone pulls the trigger on the Spray Gun. Let's look at how this looks in code: Kotlin // 1. The Compressor (Producer) val airFlow = flow { println("Compressor turned on!") emit("Air Burst 1") delay(1000) // Takes a second to build pressure emit("Air Burst 2") } // 2. The Trigger (Collector) // If we don't write this code below, the "Compressor turned on!" is NEVER printed. coroutineScope.launch { airFlow.collect { air -> println("Spray gun rec

## Learn Modern Kotlin

DevFeed: [Learn Modern Kotlin](<https://devfeed.tech/articles/learn-modern-kotlin-64150.md>)

Original publisher: [Read original article](<https://www.freecodecamp.org/news/learn-modern-kotlin/>)

Author: Beau Carnes

Published: 2026-10-02T15:23:58Z

Content type: release

Language: en

Sources: [Free Code Camp](<https://devfeed.tech/sources/freecodecamp-programming-tutorials-python-javascript-git-more.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [coroutines-flow](<https://devfeed.tech/topics/coroutines-flow.md>), [suspend function](<https://devfeed.tech/topics/suspend-function.md>), [IntelliJ IDEA](<https://devfeed.tech/topics/intellij-idea.md>), [compose-for-desktop](<https://devfeed.tech/topics/compose-for-desktop.md>)

Tags: [android-development](<https://devfeed.tech/tags/android-development.md>), [applications](<https://devfeed.tech/tags/applications.md>), [concurrency](<https://devfeed.tech/tags/concurrency.md>), [coroutines](<https://devfeed.tech/tags/coroutines.md>), [flow](<https://devfeed.tech/tags/flow.md>), [intellij-idea](<https://devfeed.tech/tags/intellij-idea.md>), [jvm](<https://devfeed.tech/tags/jvm.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [learn](<https://devfeed.tech/tags/learn.md>), [programming](<https://devfeed.tech/tags/programming.md>), [reactive-streams](<https://devfeed.tech/tags/reactive-streams.md>), [youtube](<https://devfeed.tech/tags/youtube.md>)

### AI overview

A free 10-hour Kotlin course on the freeCodeCamp.org YouTube channel covers Kotlin fundamentals, object-oriented programming, generics, coroutines, and flows. It targets Android development, backend services, and cross-platform applications.

### Source excerpt

We just published a comprehensive, free Kotlin course on the freeCodeCamp.org YouTube channel. Whether you're targeting Android development, scalable backend services, or cross-platform applications,

## Concurrent Programming in Kotlin: Ensuring Thread Safety with Mutex

DevFeed: [Concurrent Programming in Kotlin: Ensuring Thread Safety with Mutex](<https://devfeed.tech/articles/concurrent-programming-in-kotlin-ensuring-thread-safety-with-mutex-23873.md>)

Original publisher: [Read original article](<https://engineering.premise.com/concurrent-programming-in-kotlin-ensuring-thread-safety-with-mutex-5d9c6b80644b?source=rss----c5fada0a103d---4>)

Author: Kwabena Bio Berko

Published: 2023-07-18T03:33:24Z

Content type: article

Language: en

Sources: [Engineering at Premise](<https://devfeed.tech/sources/engineering-at-premise-medium.md>)

Topics: [locking](<https://devfeed.tech/topics/locking.md>), [Concurrency](<https://devfeed.tech/topics/concurrency.md>), [race-condition](<https://devfeed.tech/topics/race-condition.md>), [shared mutable state](<https://devfeed.tech/topics/shared-mutable-state.md>), [synchronization](<https://devfeed.tech/topics/synchronization.md>), [thread safe data sharing](<https://devfeed.tech/topics/thread-safe-data-sharing.md>), [multithreading](<https://devfeed.tech/topics/multithreading.md>), [Coroutines](<https://devfeed.tech/topics/coroutines.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [suspend function](<https://devfeed.tech/topics/suspend-function.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-engineer](<https://devfeed.tech/tags/android-engineer.md>), [atomic](<https://devfeed.tech/tags/atomic.md>), [component](<https://devfeed.tech/tags/component.md>), [concurrency](<https://devfeed.tech/tags/concurrency.md>), [concurrent](<https://devfeed.tech/tags/concurrent.md>), [concurrent-programming](<https://devfeed.tech/tags/concurrent-programming.md>), [concurrently](<https://devfeed.tech/tags/concurrently.md>), [coroutine](<https://devfeed.tech/tags/coroutine.md>), [coroutines](<https://devfeed.tech/tags/coroutines.md>), [data](<https://devfeed.tech/tags/data.md>), [database](<https://devfeed.tech/tags/database.md>), [engineering](<https://devfeed.tech/tags/engineering.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [mobile-app-development](<https://devfeed.tech/tags/mobile-app-development.md>), [mutex](<https://devfeed.tech/tags/mutex.md>), [safety](<https://devfeed.tech/tags/safety.md>), [software](<https://devfeed.tech/tags/software.md>), [thread](<https://devfeed.tech/tags/thread.md>), [thread-safety](<https://devfeed.tech/tags/thread-safety.md>)

### AI overview

The article describes using Kotlin's Mutex to prevent concurrent refresh calls from duplicating a remote fetch and database write. It presents two behaviors: a call can check whether the Mutex is locked and skip refresh while it is in use, or use the suspending `withLock` lambda to wait until the lock is released. Restricting access to critical sections helps prevent race conditions and keep shared data consistent, but locking too much code can serialize work, reduce parallelism, and slow the application. The article recommends limiting Mutex use to sections that require exclusive access.

### Source excerpt

By Kwabena Bio Berko, Android Engineer Photo by Chris Ried on Unsplash I have recently been experimenting with mutual exclusion(Mutex), a concept in software engineering to solve race conditions when accessing shared resources. Let's assume we have a component with a refresh function that can be accessed from multiple threads or coroutines: https://medium.com/media/e19aa2a9d57bc105b841d28061a199b8/href In the implementation of this component, the function retrieves data from a remote resource and inserts it into the local database. However, these operations need to be atomic. Now, imagine if 10 threads call this function simultaneously, or even a few milliseconds apart. What happens? If you guessed that we make 10 network calls and 10 database IO operations to save the items, then you would be right, as confirmed by the below test: https://medium.com/media/9b279658dbf87021068ee21a913dc80e/hrefhttps://medium.com/media/81cdc164ad807fd45df77389c00bd4cc/href But that's not what we want. It's definitely not resource-friendly. To address this issue, we can use a Mutex. As the name suggests, a Mutex provides mutual exclusion for a specific portion of your code, imposing restrictions on the access to that portion in situations where multiple threads or coroutines may attempt to access it concurrently. In essence, Mutex allows only one thread or coroutine to work within the confines of that portion of the code at any given time. By introducing a Mutex in our refresh function, we can ensure that only one thread is executing the critical sections of the code, preventing race conditions and ensuring atomicity of the operations. https://medium.com/media/9d88a802b4c73f14ceb4d5527158af5d/href In the example above, whenever the refresh function is called, we check to see if the Mutex is already locked or been used. If not, we lock it and then perform our network call and save the results in our local database. This means that whenever another thread or coroutine calls this refresh

## Kotlin property delegates for Datastore Preferences library

DevFeed: [Kotlin property delegates for Datastore Preferences library](<https://devfeed.tech/articles/kotlin-property-delegates-for-datastore-preferences-library-26020.md>)

Original publisher: [Read original article](<https://proandroiddev.com/kotlin-property-delegates-for-datastore-preferences-library-5d4e1cdb609b?source=rss-e93d234beac6------2>)

Author: Yahor Urbanovich

Published: 2021-08-23T15:40:08Z

Content type: tutorial

Language: en

Sources: [Yahor Urbanovich](<https://devfeed.tech/sources/stories-by-yahor-urbanovich-on-medium.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [coroutines-flow](<https://devfeed.tech/topics/coroutines-flow.md>), [Coroutines](<https://devfeed.tech/topics/coroutines.md>), [suspend function](<https://devfeed.tech/topics/suspend-function.md>), [runBlocking](<https://devfeed.tech/topics/runblocking.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-app-development](<https://devfeed.tech/tags/android-app-development.md>), [androiddev](<https://devfeed.tech/tags/androiddev.md>), [coroutines](<https://devfeed.tech/tags/coroutines.md>), [delegates](<https://devfeed.tech/tags/delegates.md>), [flow](<https://devfeed.tech/tags/flow.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [migration](<https://devfeed.tech/tags/migration.md>), [property](<https://devfeed.tech/tags/property.md>), [property-delegation](<https://devfeed.tech/tags/property-delegation.md>), [reading](<https://devfeed.tech/tags/reading.md>), [suspend](<https://devfeed.tech/tags/suspend.md>)

### AI overview

The excerpt presents Kotlin property delegates as a way to encapsulate single-value reads and writes while migrating from SharedPreferences to AndroidX DataStore Preferences. It highlights DataStore's built-in Flow and Coroutines support, compared with a SharedPreferences change-listener wrapper that emits through deprecated ConflatedBroadcastChannel before converting to Flow. The excerpt says DataStore exposes values as Flow and requires suspend functions; to read one value, the author uses Flow.first() inside runBlocking and wraps that logic in a delegate. DataStore keys can use generics, while SharedPreferences delegates need separate classes for primitive types because its getters and setters are typed. The excerpt ends before showing the final delegate implementation, so its details and limitations are not available.

### Source excerpt

Kotlin delegated property for Datastore Preferences library Recently AndroidX Datastore 1.0 was released. The moment has come, it's time to migrate away from SharedPreferences. As for me, the key benefit is the built-in support of Kotlin Flow and Coroutines. Previously we had to write our own wrapper under SharedPreferences.OnSharedPreferenceChangeListener, emit changes into ConflatedBroadcastChannel and then convert it into Flow. https://medium.com/media/b5410ce9df08d9b73427a2138a6b0a8d/href Firstly, this approach produces a lot of intermediate variables. Secondly, ConflatedBroadcastChannel deprecated and should be replaced with StateFlow. In this case, DataStore comes out as the winner. The migrated to DataStore version looks clean and simple. https://medium.com/media/cce0d485e2af9941e677dc7973a54c6f/hrefRead/write single value using SharedPreferences Let's imagine, we need to store the current App theme as String. For this purpose, we need to initialize SharedPreferences, then make two functions to read and write these values. https://medium.com/media/3bc9760a22ebd1071e4dcb21eaf8d4ba/href Well, two functions it is not so bad, but we can try to merge this into single Property. https://medium.com/media/c3babbf2b6c55bb18172f66ddc825b06/href To make it fully clear and supportable we can use the Kotlin delegation feature. As we want to read and write simultaneously, ReadWriteProperty will suit our goal. https://medium.com/media/80f370a5a5735b911c75d3a0f1d22b21/href Please take a look at the final compact version, where all logic is encapsulated inside the delegate. https://medium.com/media/39b5311b04373b1f31d3030b8b083587/hrefDataStore Preferences and missing API During migration, it turned out that the library doesn't provide an API for reading a single property. DataStore proposes to use Flow for all cases. Developers are now required to read/write the value in the scope of a suspend function. https://medium.com/media/e7c4e45e239e11bc5082f3997e5280dd/href What was e

## Kotlin Continuations

DevFeed: [Kotlin Continuations](<https://devfeed.tech/articles/kotlin-continuations-27465.md>)

Original publisher: [Read original article](<https://jorgecastilloprz.github.io/digging-into-kotlin-continuations>)

Author: Jorge Castillo

Published: 2020-09-03T11:00:00Z

Content type: article

Language: en

Sources: [Jorge Castillo](<https://devfeed.tech/sources/jorge-castillo.md>)

Topics: [suspend function](<https://devfeed.tech/topics/suspend-function.md>), [Coroutines](<https://devfeed.tech/topics/coroutines.md>), [async](<https://devfeed.tech/topics/async.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [IntelliJ IDEA](<https://devfeed.tech/topics/intellij-idea.md>)

Tags: [1-3](<https://devfeed.tech/tags/1-3.md>), [android](<https://devfeed.tech/tags/android.md>), [api](<https://devfeed.tech/tags/api.md>), [apis](<https://devfeed.tech/tags/apis.md>), [arrow](<https://devfeed.tech/tags/arrow.md>), [async](<https://devfeed.tech/tags/async.md>), [asynchronous](<https://devfeed.tech/tags/asynchronous.md>), [blocking](<https://devfeed.tech/tags/blocking.md>), [boolean](<https://devfeed.tech/tags/boolean.md>), [bridge](<https://devfeed.tech/tags/bridge.md>), [bytecode](<https://devfeed.tech/tags/bytecode.md>), [callback](<https://devfeed.tech/tags/callback.md>), [cancellation](<https://devfeed.tech/tags/cancellation.md>), [class](<https://devfeed.tech/tags/class.md>), [clicks](<https://devfeed.tech/tags/clicks.md>), [compile](<https://devfeed.tech/tags/compile.md>), [control](<https://devfeed.tech/tags/control.md>), [flow](<https://devfeed.tech/tags/flow.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [program](<https://devfeed.tech/tags/program.md>)

### AI overview

Kotlin compiles `suspend` functions into continuation-passing calls: each receives a `Continuation` that carries coroutine context and resumes execution with a success or failure result. Generated state machines and saved stack-frame state let execution pause at suspension points and continue later. Java can call the generated functions with an explicit continuation, but Kotlin's `Result` inline class complicates that route; the excerpt also describes bridging through `CompletableFuture`, calling coroutine builders from Java, or exposing Kotlin wrapper functions. For callback APIs, `suspendCoroutine` can resume a one-shot continuation, so listeners must be detached after use. The excerpt recommends `suspendCancellableCoroutine` when cancellation cleanup is needed; for repeated user events, it points to stream-based approaches such as `callbackFlow` or Arrow Fx `Stream.cancellable`.

### Source excerpt

Continuations represent the rest of a program. They are a form of control flow.