Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardKotlinCOROUTINE_SUSPENDED sentinelSingle-choice MCQ

Predict the behavior. A custom suspend function uses suspendCoroutine and stores the continuation, but ALSO returns a value synchronously by calling cont.resume(x) inside the block before the block returns. What does the suspendCoroutine machinery do, and is COROUTINE_SUSPENDED observed by the caller?

suspend fun maybeSuspend(): Int = suspendCoroutine { cont -> cont.resume(7) // resumed synchronously, inside the block }