@@ -123,8 +123,7 @@ public suspend fun Job.join() {
123
123
* This is an open class designed for extension by more specific classes that might augment the
124
124
* state and mare store addition state information for completed jobs, like their result values.
125
125
*/
126
- @Suppress(" LeakingThis" )
127
- public open class JobSupport : AbstractCoroutineContextElement (Job ), Job {
126
+ internal open class JobSupport : AbstractCoroutineContextElement (Job ), Job {
128
127
/*
129
128
=== States ===
130
129
name state class is Active?
@@ -176,7 +175,7 @@ public open class JobSupport : AbstractCoroutineContextElement(Job), Job {
176
175
* Initializes parent job.
177
176
* It shall be invoked at most once after construction after all other initialization.
178
177
*/
179
- public fun initParentJob (parent : Job ? ) {
178
+ fun initParentJob (parent : Job ? ) {
180
179
if (parent == null ) return
181
180
check(registration == null )
182
181
// directly pass HandlerNode to parent scope to optimize one closure object (see makeNode)
@@ -189,12 +188,12 @@ public open class JobSupport : AbstractCoroutineContextElement(Job), Job {
189
188
/* *
190
189
* Returns current state of this job.
191
190
*/
192
- internal fun getState (): Any? = state
191
+ fun getState (): Any? = state
193
192
194
193
/* *
195
194
* Tries to update current [state][getState] of this job.
196
195
*/
197
- protected fun updateState (expect : Any , update : Any? ): Boolean {
196
+ fun updateState (expect : Any , update : Any? ): Boolean {
198
197
require(expect is Active && update !is Active ) // only active -> inactive transition is allowed
199
198
if (! STATE .compareAndSet(this , expect, update)) return false
200
199
// #1. Update linked state before invoking completion handlers
@@ -229,9 +228,9 @@ public open class JobSupport : AbstractCoroutineContextElement(Job), Job {
229
228
return true
230
229
}
231
230
232
- public final override val isActive: Boolean get() = state is Active
231
+ final override val isActive: Boolean get() = state is Active
233
232
234
- public final override fun onCompletion (handler : CompletionHandler ): Job .Registration {
233
+ final override fun onCompletion (handler : CompletionHandler ): Job .Registration {
235
234
var nodeCache: JobNode ? = null
236
235
while (true ) { // lock-free loop on state
237
236
val state = this .state
@@ -265,7 +264,7 @@ public open class JobSupport : AbstractCoroutineContextElement(Job), Job {
265
264
}
266
265
}
267
266
268
- internal fun removeNode (node : JobNode ) {
267
+ fun removeNode (node : JobNode ) {
269
268
// remove logic depends on the state of the job
270
269
while (true ) { // lock-free loop on job state
271
270
val state = this .state
@@ -290,7 +289,7 @@ public open class JobSupport : AbstractCoroutineContextElement(Job), Job {
290
289
}
291
290
}
292
291
293
- public final override fun cancel (reason : Throwable ? ): Boolean {
292
+ final override fun cancel (reason : Throwable ? ): Boolean {
294
293
while (true ) { // lock-free loop on state
295
294
val state = this .state as ? Active ? : return false // quit if not active anymore
296
295
if (updateState(state, Cancelled (reason))) return true
@@ -300,19 +299,19 @@ public open class JobSupport : AbstractCoroutineContextElement(Job), Job {
300
299
/* *
301
300
* Override to make linked state changes before completion handlers are invoked.
302
301
*/
303
- protected open fun onStateUpdate (update : Any? ) {}
302
+ open fun onStateUpdate (update : Any? ) {}
304
303
305
304
/* *
306
305
* Override to process any exceptions that were encountered while invoking [onCompletion] handlers.
307
306
*/
308
- protected open fun handleCompletionException (closeException : Throwable ) {
307
+ open fun handleCompletionException (closeException : Throwable ) {
309
308
throw closeException
310
309
}
311
310
312
311
/* *
313
312
* Override for post-completion actions that need to do something with the state.
314
313
*/
315
- protected open fun afterCompletion (state : Any? ) {}
314
+ open fun afterCompletion (state : Any? ) {}
316
315
317
316
private fun makeNode (handler : CompletionHandler ): JobNode =
318
317
(handler as ? JobNode )?.also { require(it.job == = this ) }
@@ -321,7 +320,7 @@ public open class JobSupport : AbstractCoroutineContextElement(Job), Job {
321
320
/* *
322
321
* Marker interface for active [state][getState] of a job.
323
322
*/
324
- public interface Active
323
+ internal interface Active
325
324
326
325
private object Empty : Active
327
326
@@ -330,15 +329,15 @@ public open class JobSupport : AbstractCoroutineContextElement(Job), Job {
330
329
/* *
331
330
* Abstract class for a [state][getState] of a job that had completed exceptionally, including cancellation.
332
331
*/
333
- public abstract class CompletedExceptionally {
332
+ internal abstract class CompletedExceptionally {
334
333
abstract val cancelReason: Throwable // original reason or fresh CancellationException
335
334
abstract val exception: Throwable // the exception to be thrown in continuation
336
335
}
337
336
338
337
/* *
339
338
* Represents a [state][getState] of a cancelled job.
340
339
*/
341
- public class Cancelled (specifiedReason : Throwable ? ) : CompletedExceptionally() {
340
+ internal class Cancelled (specifiedReason : Throwable ? ) : CompletedExceptionally() {
342
341
@Volatile
343
342
private var _cancelReason = specifiedReason // materialize CancellationException on first need
344
343
@@ -359,7 +358,7 @@ public open class JobSupport : AbstractCoroutineContextElement(Job), Job {
359
358
/* *
360
359
* Represents a [state][getState] of a failed job.
361
360
*/
362
- public class Failed (override val exception : Throwable ) : CompletedExceptionally() {
361
+ internal class Failed (override val exception : Throwable ) : CompletedExceptionally() {
363
362
override val cancelReason: Throwable
364
363
get() = exception
365
364
}
0 commit comments