File tree Expand file tree Collapse file tree 1 file changed +14
-6
lines changed
kotlinx-coroutines-core/common/src/selects Expand file tree Collapse file tree 1 file changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -632,16 +632,24 @@ internal open class SelectImplementation<R> constructor(
632632 // is invoked at the very end.
633633 selectedClause.invokeBlock(blockArgument)
634634 } else {
635+ // TAIL-CALL OPTIMIZATION: the `suspend`
636+ // function is invoked at the very end.
637+ // However, internally this `suspend` function
638+ // constructs a state machine to recover a
639+ // possible stack-trace.
640+ selectedClause.invokeBlockRecoveringException(blockArgument)
641+ }
642+ }
643+
644+ private suspend fun ClauseData<R>.invokeBlockRecoveringException (blockArgument : Any? ): R =
645+ try {
635646 // In the debug mode, we need to recover
636647 // the stack-trace of possible exception.
637648 // Thus, the tail-call optimization cannot be applied.
638- try {
639- selectedClause.invokeBlock(blockArgument)
640- } catch (e: Throwable ) {
641- throw recoverStackTrace(e)
642- }
649+ invokeBlock(blockArgument)
650+ } catch (e: Throwable ) {
651+ throw recoverStackTrace(e)
643652 }
644- }
645653
646654 /* *
647655 * Invokes all [DisposableHandle]-s provided via
You can’t perform that action at this time.
0 commit comments