@@ -150,14 +150,14 @@ public typealias ProcessResultFunction = (clauseObject: Any, param: Any?, clause
150
150
* cancellation while dispatching. Unfortunately, we cannot pass this function only in [SelectInstance.trySelect],
151
151
* as [SelectInstance.selectInRegistrationPhase] can be called when the coroutine is already cancelled.
152
152
*/
153
+ @InternalCoroutinesApi
153
154
public typealias OnCancellationConstructor = (select: SelectInstance <* >, param: Any? , internalResult: Any? ) -> (Throwable ) -> Unit
154
155
155
156
/* *
156
157
* Clause for [select] expression without additional parameters that does not select any value.
157
158
*/
158
159
public interface SelectClause0 : SelectClause
159
- @InternalCoroutinesApi
160
- public class SelectClause0Impl (
160
+ internal class SelectClause0Impl (
161
161
override val clauseObject : Any ,
162
162
override val regFunc : RegistrationFunction ,
163
163
override val onCancellationConstructor : OnCancellationConstructor ? = null
@@ -171,8 +171,7 @@ private val DUMMY_PROCESS_RESULT_FUNCTION: ProcessResultFunction = { _, _, _ ->
171
171
* Clause for [select] expression without additional parameters that selects value of type [Q].
172
172
*/
173
173
public interface SelectClause1 <out Q > : SelectClause
174
- @InternalCoroutinesApi
175
- public class SelectClause1Impl <Q >(
174
+ internal class SelectClause1Impl <Q >(
176
175
override val clauseObject : Any ,
177
176
override val regFunc : RegistrationFunction ,
178
177
override val processResFunc : ProcessResultFunction ,
@@ -183,8 +182,7 @@ public class SelectClause1Impl<Q>(
183
182
* Clause for [select] expression with additional parameter of type [P] that selects value of type [Q].
184
183
*/
185
184
public interface SelectClause2 <in P , out Q > : SelectClause
186
- @InternalCoroutinesApi
187
- public class SelectClause2Impl <P , Q >(
185
+ internal class SelectClause2Impl <P , Q >(
188
186
override val clauseObject : Any ,
189
187
override val regFunc : RegistrationFunction ,
190
188
override val processResFunc : ProcessResultFunction ,
@@ -348,7 +346,7 @@ internal open class SelectImplementation<R> constructor(
348
346
it == = STATE_REG || it is List <* >
349
347
}
350
348
/* *
351
- * Returns `true` if this `select` is already selected or cancelled ;
349
+ * Returns `true` if this `select` is already selected;
352
350
* thus, other parties are bound to fail when making a rendezvous with it.
353
351
*/
354
352
private val isSelected
@@ -437,8 +435,9 @@ internal open class SelectImplementation<R> constructor(
437
435
* updates the state to this clause reference.
438
436
*/
439
437
protected fun ClauseData<R>.register (reregister : Boolean = false) {
438
+ assert { state.value !is Cancelled }
440
439
// 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
442
441
// For new clauses, check that there does not exist
443
442
// another clause with the same object.
444
443
if (! reregister) checkClauseObject(clauseObject)
@@ -459,13 +458,7 @@ internal open class SelectImplementation<R> constructor(
459
458
} else {
460
459
// This clause has been selected!
461
460
// 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
469
462
}
470
463
}
471
464
@@ -529,8 +522,6 @@ internal open class SelectImplementation<R> constructor(
529
522
cont.resume(Unit , curState.createOnCancellationAction(this , internalResult))
530
523
return @sc
531
524
}
532
- // Cancelled
533
- curState is Cancelled -> return @sc
534
525
// This `select` cannot be in any other state.
535
526
else -> error(" unexpected state: $curState " )
536
527
}
@@ -787,6 +778,8 @@ private val NO_RESULT = Symbol("NO_RESULT")
787
778
// We use this marker parameter objects to distinguish
788
779
// SelectClause[0,1,2] and invoke the user-specified block correctly.
789
780
@SharedImmutable
781
+ @JvmField
790
782
internal val PARAM_CLAUSE_0 = Symbol (" PARAM_CLAUSE_0" )
791
783
@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