@@ -450,8 +450,8 @@ internal abstract class AbstractSendChannel<E> : SendChannel<E> {
450
450
@JvmField val select : SelectInstance <R >,
451
451
@JvmField val block : suspend (SendChannel <E >) -> R
452
452
) : Send(), DisposableHandle {
453
- override fun tryResumeSend (otherOp : PrepareOp ? ): Any ? =
454
- select.trySelectOther(otherOp)
453
+ override fun tryResumeSend (otherOp : PrepareOp ? ): Symbol ? =
454
+ select.trySelectOther(otherOp) as Symbol ? // must return symbol
455
455
456
456
override fun completeResumeSend () {
457
457
block.startCoroutine(receiver = channel, completion = select.completion)
@@ -473,7 +473,7 @@ internal abstract class AbstractSendChannel<E> : SendChannel<E> {
473
473
@JvmField val element : E
474
474
) : Send() {
475
475
override val pollResult: Any? get() = element
476
- override fun tryResumeSend (otherOp : PrepareOp ? ): Any? = RESUME_TOKEN .also { otherOp?.finishPrepare() }
476
+ override fun tryResumeSend (otherOp : PrepareOp ? ): Symbol ? = RESUME_TOKEN .also { otherOp?.finishPrepare() }
477
477
override fun completeResumeSend () {}
478
478
override fun resumeSendClosed (closed : Closed <* >) {}
479
479
}
@@ -898,9 +898,11 @@ internal abstract class AbstractChannel<E> : AbstractSendChannel<E>(), Channel<E
898
898
}
899
899
900
900
@Suppress(" IMPLICIT_CAST_TO_ANY" )
901
- override fun tryResumeReceive (value : E , otherOp : PrepareOp ? ): Any ? {
901
+ override fun tryResumeReceive (value : E , otherOp : PrepareOp ? ): Symbol ? {
902
902
otherOp?.finishPrepare()
903
- return cont.tryResume(resumeValue(value), otherOp?.desc)
903
+ val token = cont.tryResume(resumeValue(value), otherOp?.desc) ? : return null
904
+ assert { token == = RESUME_TOKEN } // the only other possible result
905
+ return RESUME_TOKEN
904
906
}
905
907
906
908
override fun completeResumeReceive (value : E ) = cont.completeResume(RESUME_TOKEN )
@@ -919,9 +921,11 @@ internal abstract class AbstractChannel<E> : AbstractSendChannel<E>(), Channel<E
919
921
@JvmField val iterator : Itr <E >,
920
922
@JvmField val cont : CancellableContinuation <Boolean >
921
923
) : Receive<E>() {
922
- override fun tryResumeReceive (value : E , otherOp : PrepareOp ? ): Any ? {
924
+ override fun tryResumeReceive (value : E , otherOp : PrepareOp ? ): Symbol ? {
923
925
otherOp?.finishPrepare()
924
- return cont.tryResume(true , otherOp?.desc)
926
+ val token = cont.tryResume(true , otherOp?.desc) ? : return null
927
+ assert { token == = RESUME_TOKEN } // the only other possible result
928
+ return RESUME_TOKEN
925
929
}
926
930
927
931
override fun completeResumeReceive (value : E ) {
@@ -953,8 +957,8 @@ internal abstract class AbstractChannel<E> : AbstractSendChannel<E>(), Channel<E
953
957
@JvmField val block : suspend (Any? ) -> R ,
954
958
@JvmField val receiveMode : Int
955
959
) : Receive<E>(), DisposableHandle {
956
- override fun tryResumeReceive (value : E , otherOp : PrepareOp ? ): Any ? =
957
- select.trySelectOther(otherOp)
960
+ override fun tryResumeReceive (value : E , otherOp : PrepareOp ? ): Symbol ? =
961
+ select.trySelectOther(otherOp) as Symbol ?
958
962
959
963
@Suppress(" UNCHECKED_CAST" )
960
964
override fun completeResumeReceive (value : E ) {
@@ -1019,7 +1023,7 @@ internal abstract class Send : LockFreeLinkedListNode() {
1019
1023
// RETRY_ATOMIC for retry (only when otherOp != null),
1020
1024
// RESUME_TOKEN on success (call completeResumeSend)
1021
1025
// Must call otherOp?.finishPrepare() before deciding on result other than RETRY_ATOMIC
1022
- abstract fun tryResumeSend (otherOp : PrepareOp ? ): Any ?
1026
+ abstract fun tryResumeSend (otherOp : PrepareOp ? ): Symbol ?
1023
1027
abstract fun completeResumeSend ()
1024
1028
abstract fun resumeSendClosed (closed : Closed <* >)
1025
1029
}
@@ -1033,7 +1037,7 @@ internal interface ReceiveOrClosed<in E> {
1033
1037
// RETRY_ATOMIC for retry (only when otherOp != null),
1034
1038
// RESUME_TOKEN on success (call completeResumeReceive)
1035
1039
// Must call otherOp?.finishPrepare() before deciding on result other than RETRY_ATOMIC
1036
- fun tryResumeReceive (value : E , otherOp : PrepareOp ? ): Any ?
1040
+ fun tryResumeReceive (value : E , otherOp : PrepareOp ? ): Symbol ?
1037
1041
fun completeResumeReceive (value : E )
1038
1042
}
1039
1043
@@ -1045,9 +1049,11 @@ internal class SendElement(
1045
1049
override val pollResult : Any? ,
1046
1050
@JvmField val cont : CancellableContinuation <Unit >
1047
1051
) : Send() {
1048
- override fun tryResumeSend (otherOp : PrepareOp ? ): Any ? {
1052
+ override fun tryResumeSend (otherOp : PrepareOp ? ): Symbol ? {
1049
1053
otherOp?.finishPrepare()
1050
- return cont.tryResume(Unit , otherOp?.desc)
1054
+ val token = cont.tryResume(Unit , otherOp?.desc)
1055
+ assert { token == = RESUME_TOKEN } // the only other possible result
1056
+ return RESUME_TOKEN
1051
1057
}
1052
1058
override fun completeResumeSend () = cont.completeResume(RESUME_TOKEN )
1053
1059
override fun resumeSendClosed (closed : Closed <* >) = cont.resumeWithException(closed.sendException)
@@ -1065,9 +1071,9 @@ internal class Closed<in E>(
1065
1071
1066
1072
override val offerResult get() = this
1067
1073
override val pollResult get() = this
1068
- override fun tryResumeSend (otherOp : PrepareOp ? ): Any ? = RESUME_TOKEN .also { otherOp?.finishPrepare() }
1074
+ override fun tryResumeSend (otherOp : PrepareOp ? ): Symbol ? = RESUME_TOKEN .also { otherOp?.finishPrepare() }
1069
1075
override fun completeResumeSend () {}
1070
- override fun tryResumeReceive (value : E , otherOp : PrepareOp ? ): Any ? = RESUME_TOKEN .also { otherOp?.finishPrepare() }
1076
+ override fun tryResumeReceive (value : E , otherOp : PrepareOp ? ): Symbol ? = RESUME_TOKEN .also { otherOp?.finishPrepare() }
1071
1077
override fun completeResumeReceive (value : E ) {}
1072
1078
override fun resumeSendClosed (closed : Closed <* >) = assert { false } // "Should be never invoked"
1073
1079
override fun toString (): String = " Closed[$closeCause ]"
0 commit comments