File tree 1 file changed +14
-6
lines changed
kotlinx-coroutines-core/common/src/selects
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(
632
632
// is invoked at the very end.
633
633
selectedClause.invokeBlock(blockArgument)
634
634
} 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 {
635
646
// In the debug mode, we need to recover
636
647
// the stack-trace of possible exception.
637
648
// 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)
643
652
}
644
- }
645
653
646
654
/* *
647
655
* Invokes all [DisposableHandle]-s provided via
You can’t perform that action at this time.
0 commit comments