Created
October 4, 2025 03:08
-
-
Save anandwana001/bc7be3d1c05273dd255ad67e8b0f8f07 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ❌ 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