1 /* 2 * Copyright 2016-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 */ 4 5 package kotlinx.coroutines.test.internal 6 7 import kotlinx.coroutines.* 8 9 /** 10 * A variant of [SupervisorJob] that additionally notifies about child failures via a callback. 11 */ 12 @Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE", "CANNOT_OVERRIDE_INVISIBLE_MEMBER") 13 internal class ReportingSupervisorJob(parent: Job? = null, val onChildCancellation: (Throwable) -> Unit) : 14 JobImpl(parent) { childCancellednull15 override fun childCancelled(cause: Throwable): Boolean = 16 try { 17 onChildCancellation(cause) 18 } catch (e: Throwable) { 19 cause.addSuppressed(e) 20 /* the coroutine context does not matter here, because we're only interested in reporting this exception 21 to the platform-specific global handler, not to a [CoroutineExceptionHandler] of any sort. */ 22 handleCoroutineException(this, cause) <lambda>null23 }.let { false } 24 } 25