Skip to content

Instantly share code, notes, and snippets.

@anandwana001
Created October 4, 2025 03:08
Show Gist options
  • Select an option

  • Save anandwana001/bc7be3d1c05273dd255ad67e8b0f8f07 to your computer and use it in GitHub Desktop.

Select an option

Save anandwana001/bc7be3d1c05273dd255ad67e8b0f8f07 to your computer and use it in GitHub Desktop.
// ❌ Wrong: Blocking call without withContext
suspend fun badExample() {
Thread.sleep(1000) // Blocks the thread!
}
// ✅ Correct: Use delay for coroutines
suspend fun goodExample() {
delay(1000) // Suspends without blocking
}
// ✅ Correct: Use withContext for blocking calls
suspend fun blockingOperation() = withContext(Dispatchers.IO) {
Thread.sleep(1000) // OK on IO dispatcher
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment