Ruang penulis
SEBUAH JURNAL TENTANG TEKNOLOGI

Belajar hal baru.
Tulis. Bagikan.

Ruang untuk merangkai pengetahuan, satu baris kode setiap hari.
Temukan tutorial, ide, dan catatan dari perjalanan belajar.

1914 catatan & terus bertumbuh
PILIHAN EDITOR
Java

Memahami Java Stream: olah koleksi dengan lebih ringkas

Pelajari alur filter, map, dan collect untuk mengolah data Java dengan kode yang mudah dibaca.

D Tim Diary Coding · 1 menit baca
UNTUK RASA INGIN TAHUMU

Catatan terbaru.

KOTLIN / CATATAN</>
Kotlin03 Jul 2026

How do I understand the coroutine lifecycle in Kotlin?

Kotlin coroutine lifecycle: the mental model A Kotlin coroutine is a lightweight concurrent task that runs inside a CoroutineScope and is controlled by a Job. The lifecycle is mostly about the state of that Job. At a high level: New → Active → Completing → Completed ↘ Cancelling → Cancelled Most of the time, you […]

Wayan · 6 menit baca
KOTLIN / CATATAN</>
Kotlin03 Jul 2026

How do I cancel a coroutine in Kotlin safely?

In Kotlin, you cancel a coroutine safely by calling cancel() on its Job or scope, and making sure the coroutine code is cooperative: it should suspend regularly or check for cancellation. Basic example import kotlinx.coroutines.* fun main() = runBlocking { val job = launch { try { repeat(1_000) { i -> println("Working $i") delay(500) // […]

Wayan · 2 menit baca
KOTLIN / CATATAN</>
Kotlin03 Jul 2026

How do I run coroutines in parallel using async and await in Kotlin?

In Kotlin, use async to start concurrent work inside a coroutine scope, then call await() to get each result. Basic example: import kotlinx.coroutines.* suspend fun fetchUser(): String { delay(1000) return "User" } suspend fun fetchPosts(): List<String> { delay(1000) return listOf("Post 1", "Post 2") } fun main() = runBlocking { val userDeferred = async { fetchUser() […]

Wayan · 2 menit baca
KOTLIN / CATATAN</>
Kotlin03 Jul 2026

How do I write a suspend function in Kotlin?

In Kotlin, a suspend function is declared with the suspend modifier. suspend fun fetchUser(): User { // Can call other suspend functions here return api.getUser() } A suspend function can pause without blocking the thread and later resume. It is commonly used with coroutines for asynchronous work. Example: import kotlinx.coroutines.delay import kotlinx.coroutines.runBlocking suspend fun greetAfterDelay() […]

Wayan · 1 menit baca
KOTLIN / CATATAN</>
Kotlin03 Jul 2026

How do I use delay instead of Thread.sleep in Kotlin coroutines?

Use kotlinx.coroutines.delay(…) inside a coroutine instead of Thread.sleep(…). Thread.sleep blocks the current thread. delay suspends the coroutine without blocking the thread, so other coroutines can keep running. import kotlinx.coroutines.delay import kotlinx.coroutines.runBlocking fun main() = runBlocking { println("Before delay") delay(1_000) // suspends for 1 second, does not block the thread println("After delay") } If you currently […]

Wayan · 1 menit baca
KOTLIN / CATATAN</>
Kotlin03 Jul 2026

How do I launch a coroutine in Kotlin using launch and runBlocking?

In Kotlin, you can use runBlocking to start a coroutine scope that blocks the current thread until its coroutines finish, and launch to start a new coroutine inside that scope. import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking fun main() = runBlocking { launch { println("Coroutine is running") } println("Main coroutine continues") } Output may look like: Main coroutine […]

Wayan · 1 menit baca

Pengetahuan tumbuh ketika dibagikan.

Simpan rasa ingin tahu. Selalu ada hal baru untuk dipelajari.

Jelajahi catatan ↗
Putu Adi Guna Permana
TENTANG PENULIS

Dr (C). Ir. Putu Adi Guna Permana, S.Kom., M.Kom., IPM., ASEAN Eng.

Penulis dan pendiri Diary Coding — berbagi catatan, tutorial, dan pengalaman seputar pemrograman untuk siapa pun yang ingin terus belajar.