[core] CoroutineOnDemandValueScope: ignore multiple finishImpl

This commit is contained in:
Him188 2023-04-16 10:20:44 +01:00
parent e76cdfb5df
commit 1b122190f1
No known key found for this signature in database
GPG Key ID: BA439CDDCF652375

View File

@ -99,7 +99,7 @@ internal class CoroutineOnDemandValueScope<T, V>(
private fun finishImpl(exception: Throwable?) {
state.loop { state ->
when (state) {
is ProducerState.Finished -> throw state.createAlreadyFinishedException(exception)
is ProducerState.Finished -> {} // ignore
else -> {
if (compareAndSetState(state, ProducerState.Finished(state, exception))) {
val cancellationException = kotlinx.coroutines.CancellationException("Finished", exception)
@ -153,6 +153,7 @@ internal class CoroutineOnDemandValueScope<T, V>(
}
return null
}
else -> throw IllegalProducerStateException(state)
}
}