@@ -150,14 +150,14 @@ public typealias ProcessResultFunction = (clauseObject: Any, param: Any?, clause
150150 * cancellation while dispatching. Unfortunately, we cannot pass this function only in [SelectInstance.trySelect],
151151 * as [SelectInstance.selectInRegistrationPhase] can be called when the coroutine is already cancelled.
152152 */
153+ @InternalCoroutinesApi
153154public typealias OnCancellationConstructor = (select: SelectInstance <* >, param: Any? , internalResult: Any? ) -> (Throwable ) -> Unit
154155
155156/* *
156157 * Clause for [select] expression without additional parameters that does not select any value.
157158 */
158159public interface SelectClause0 : SelectClause
159- @InternalCoroutinesApi
160- public class SelectClause0Impl (
160+ internal class SelectClause0Impl (
161161 override val clauseObject : Any ,
162162 override val regFunc : RegistrationFunction ,
163163 override val onCancellationConstructor : OnCancellationConstructor ? = null
@@ -171,8 +171,7 @@ private val DUMMY_PROCESS_RESULT_FUNCTION: ProcessResultFunction = { _, _, _ ->
171171 * Clause for [select] expression without additional parameters that selects value of type [Q].
172172 */
173173public interface SelectClause1 <out Q > : SelectClause
174- @InternalCoroutinesApi
175- public class SelectClause1Impl <Q >(
174+ internal class SelectClause1Impl <Q >(
176175 override val clauseObject : Any ,
177176 override val regFunc : RegistrationFunction ,
178177 override val processResFunc : ProcessResultFunction ,
@@ -183,8 +182,7 @@ public class SelectClause1Impl<Q>(
183182 * Clause for [select] expression with additional parameter of type [P] that selects value of type [Q].
184183 */
185184public interface SelectClause2 <in P , out Q > : SelectClause
186- @InternalCoroutinesApi
187- public class SelectClause2Impl <P , Q >(
185+ internal class SelectClause2Impl <P , Q >(
188186 override val clauseObject : Any ,
189187 override val regFunc : RegistrationFunction ,
190188 override val processResFunc : ProcessResultFunction ,
@@ -348,7 +346,7 @@ internal open class SelectImplementation<R> constructor(
348346 it == = STATE_REG || it is List <* >
349347 }
350348 /* *
351- * Returns `true` if this `select` is already selected or cancelled ;
349+ * Returns `true` if this `select` is already selected;
352350 * thus, other parties are bound to fail when making a rendezvous with it.
353351 */
354352 private val isSelected
@@ -437,8 +435,9 @@ internal open class SelectImplementation<R> constructor(
437435 * updates the state to this clause reference.
438436 */
439437 protected fun ClauseData<R>.register (reregister : Boolean = false) {
438+ assert { state.value !is Cancelled }
440439 // Is there already selected clause?
441- if (state.value.let { it is ClauseData <* > || it is Cancelled }) return
440+ if (state.value.let { it is ClauseData <* > }) return
442441 // For new clauses, check that there does not exist
443442 // another clause with the same object.
444443 if (! reregister) checkClauseObject(clauseObject)
@@ -459,13 +458,7 @@ internal open class SelectImplementation<R> constructor(
459458 } else {
460459 // This clause has been selected!
461460 // Update the state correspondingly.
462- state.update {
463- if (it is Cancelled ) {
464- createOnCancellationAction(this @SelectImplementation, internalResult)?.invoke(it.cause)
465- return
466- }
467- this
468- }
461+ state.value = this
469462 }
470463 }
471464
@@ -529,8 +522,6 @@ internal open class SelectImplementation<R> constructor(
529522 cont.resume(Unit , curState.createOnCancellationAction(this , internalResult))
530523 return @sc
531524 }
532- // Cancelled
533- curState is Cancelled -> return @sc
534525 // This `select` cannot be in any other state.
535526 else -> error(" unexpected state: $curState " )
536527 }
@@ -787,6 +778,8 @@ private val NO_RESULT = Symbol("NO_RESULT")
787778// We use this marker parameter objects to distinguish
788779// SelectClause[0,1,2] and invoke the user-specified block correctly.
789780@SharedImmutable
781+ @JvmField
790782internal val PARAM_CLAUSE_0 = Symbol (" PARAM_CLAUSE_0" )
791783@SharedImmutable
792- internal val PARAM_CLAUSE_1 = Symbol (" PARAM_CLAUSE_1" )
784+ @JvmField
785+ internal val PARAM_CLAUSE_1 = Symbol (" PARAM_CLAUSE_1" )
0 commit comments