Zum Hauptinhalt springen
Echtzeit-Radar & Feeds
Alle RSS Feeds ➔
👥 Community & Social
IT Security NachrichtenNew infosec products of the week: October 2, 2026(02.10.2026 um 06:00 Uhr)
•
IT Security NachrichtenERP-Migration: Kostenfalle Schnittstellen(02.10.2026 um 05:34 Uhr)
•
Android Tipps & SecurityAmazon reduziert eure Prime-Gebühr jetzt auf den alten Preis(02.10.2026 um 06:00 Uhr)
•••
Sicherheitslücken (CVE)CVE-2026-21140 | Samsung Devices access control (EUVD-2026-91157)(02.10.2026 um 05:08 Uhr)
••••
Sichere ProgrammierungWhat Can NSL Actually Do? — A Look at Nova Signal Language(02.10.2026 um 05:14 Uhr)
•
IT Security NachrichtenNew infosec products of the week: October 2, 2026(02.10.2026 um 06:00 Uhr)
•
IT Security NachrichtenERP-Migration: Kostenfalle Schnittstellen(02.10.2026 um 05:34 Uhr)
•
Android Tipps & SecurityAmazon reduziert eure Prime-Gebühr jetzt auf den alten Preis(02.10.2026 um 06:00 Uhr)
•••
Sicherheitslücken (CVE)CVE-2026-21140 | Samsung Devices access control (EUVD-2026-91157)(02.10.2026 um 05:08 Uhr)
••••
Sichere ProgrammierungWhat Can NSL Actually Do? — A Look at Nova Signal Language(02.10.2026 um 05:14 Uhr)
•
Intelligence View
⚡ tsecurity.de Intelligence

Kotlin Coroutines Cheat Sheet

⚙️ Kotlin Coroutines Cheat Sheet (For Android Devs) I like to share content that I use during study and work. This is a cheatsheet that I used when developing w…

Beitrag
0
Seite
0
↗ Quelle (dev.to)
Social ReaktionenReagiere als Erste:r — dein Feedback zählt!




⚙️ Kotlin Coroutines Cheat Sheet (For Android Devs)



I like to share content that I use during study and work.

This is a cheatsheet that I used when developing with coroutines.



Coroutines are lightweight threads used for asynchronous and concurrent programming in Kotlin.


They allow you to run tasks like network or DB operations without blocking the main thread.









🔹 Core Keywords & Builders




















































Keyword / Builder Description
suspend Marks a function that can be paused and resumed later
launch Starts a coroutine that doesn’t return a result
async Starts a coroutine that returns a Deferred result
await() Waits for the result of an async coroutine
withContext() Switches the coroutine context (e.g., Main, IO)
runBlocking Starts a blocking coroutine (usually for testing)
coroutineScope Creates a new scope that waits for all its children
supervisorScope Similar to coroutineScope but failures don’t cancel siblings
delay() Non-blocking sleep function
yield() Yields execution to other coroutines temporarily








🔹 Dispatchers




























Dispatcher Used for
Dispatchers.Main UI operations (Android main thread)
Dispatchers.IO I/O tasks: networking, DB, file access
Dispatchers.Default CPU-intensive work
Dispatchers.Unconfined Executes in current thread (advanced use)








🔹 Example 1: Basic Launch






import kotlinx.coroutines.*

fun main() = runBlocking {
launch {
delay(1000)
println("World!")
}
println("Hello,")
}









Output:



Hello,

World!







🔹 Example 2: async/await






import kotlinx.coroutines.*

suspend fun fetchUser(): String {
delay(1000)
return "Bruno"
}

suspend fun fetchPosts(): List<String> {
delay(1000)
return listOf("Post 1", "Post 2")
}

fun main() = runBlocking {
val user = async { fetchUser() }
val posts = async { fetchPosts() }
println("User: ${user.await()}, Posts: ${posts.await()}")
}









Output:



User: Bruno, Posts: [Post 1, Post 2]







🔹 Example 3: withContext






import kotlinx.coroutines.*

suspend fun loadUserData() = withContext(Dispatchers.IO) {
// background work
"User data loaded"
}

fun main() = runBlocking {
val result = loadUserData()
println(result)
}









Output:



User data loaded







🔹 Flow basics






import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*

fun numbersFlow(): Flow<Int> = flow {
for (i in 1..3) {
emit(i)
delay(100)
}
}

fun main() = runBlocking {
numbersFlow()
.map { it * 2 }
.collect { println(it) }
}









Output:



2

4

6




You can try these examples yourself on Kotlin Playground.

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Kotlin Coroutines Cheat Sheet

Thematisch verwandte Begriffe: Kotlin, Coroutines, Cheat, Sheet · 6 Treffer

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

💬 Kommentare werden geladen…
Zum Aktualisieren ziehen
tsecurity.de Icon
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag