Intermediate 8 min readKotlin 2.0

Kotlin suspend Functions โ€” Pause Without Blocking

The suspend modifier marks functions that can pause and resume. They are the building blocks of readable asynchronous Kotlin code.

What You Will Learn

  • What suspend means at compile time
  • How suspend differs from blocking calls
  • Call suspend functions from coroutines
  • Why suspend cannot be called from regular code
  • Common suspend APIs like delay()

What Does suspend Mean?

A suspend function can pause its execution at suspension points and resume later without blocking the thread. The Kotlin compiler transforms suspend functions into a state machine. You can only call suspend functions from other suspend functions or from a coroutine builder like runBlocking or launch.

Basic suspend Function

kotlin
import kotlinx.coroutines.*

suspend fun greet(): String {
    delay(300)
    return "Hello from suspend"
}

fun main() = runBlocking {
    println(greet())
}
Output
Hello from suspend

greet() is suspend because it calls delay(). runBlocking provides a coroutine context so greet() can run.

Beginner Tip: delay() is the simplest way to see suspension โ€” it frees the thread while waiting.
Dependency required: implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0")

Suspend vs Blocking

Thread.sleep() blocks the thread. delay() suspends the coroutine. Under load, suspension scales far better because one thread can run many coroutines.

delay Does Not Block the Thread

kotlin
import kotlinx.coroutines.*

fun main() = runBlocking {
    launch {
        delay(500)
        println("Coroutine done")
    }
    println("Main continues immediately")
}
Output
Main continues immediately Coroutine done

Main prints first because delay suspends only the child coroutine, not the whole thread.

Practice Exercise

Exercisemultiple choice

Where can you call a suspend function?

Quick Quiz

Quick Quiz

What does the suspend keyword tell the compiler?

Frequently Asked Questions

Related Tutorials

Last updated: 2026-05-19Kotlin 2.0

Written by KotlinGuide Editorial Team ยท Reviewed by KotlinGuide Technical Review