in ktor-io/jvm/src/io/ktor/utils/io/jvm/javaio/Blocking.kt [196:231]
fun submitAndAwait(jobToken: Any): Int {
val thread = Thread.currentThread()
var cont: Continuation<Any>? = null
state.update { value ->
when (value) {
is Continuation<*> -> {
@Suppress("UNCHECKED_CAST")
cont = value as Continuation<Any>
thread
}
is Unit -> {
return result.value
}
is Throwable -> {
throw value
}
is Thread -> throw IllegalStateException("There is already thread owning adapter")
this -> throw IllegalStateException("Not yet started")
else -> NoWhenBranchMatchedException()
}
}
cont!!.resume(jobToken)
parkingLoop(thread)
state.value.let { state ->
if (state is Throwable) {
throw state
}
}
return result.value
}