Skip to content

Commit de238eb

Browse files
committed
CoroutineExceptionHandler pseudo-constructor is replaced with top-level fun
1 parent e7472ee commit de238eb

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/CoroutineExceptionHandler.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,11 @@ public interface CoroutineExceptionHandler : CoroutineContext.Element {
5656
/**
5757
* Creates new [CoroutineExceptionHandler] instance.
5858
* @param handler a function which handles exception thrown by a coroutine
59+
* @suppress **Deprecated**
5960
*/
61+
@Deprecated("Replaced with top-level function", level = DeprecationLevel.HIDDEN)
6062
public operator inline fun invoke(crossinline handler: (CoroutineContext, Throwable) -> Unit): CoroutineExceptionHandler =
61-
object: AbstractCoroutineContextElement(Key), CoroutineExceptionHandler {
62-
override fun handleException(context: CoroutineContext, exception: Throwable) =
63-
handler.invoke(context, exception)
64-
}
63+
CoroutineExceptionHandler(handler)
6564
}
6665

6766
/**
@@ -70,3 +69,13 @@ public interface CoroutineExceptionHandler : CoroutineContext.Element {
7069
*/
7170
public fun handleException(context: CoroutineContext, exception: Throwable)
7271
}
72+
73+
/**
74+
* Creates new [CoroutineExceptionHandler] instance.
75+
* @param handler a function which handles exception thrown by a coroutine
76+
*/
77+
public inline fun CoroutineExceptionHandler(crossinline handler: (CoroutineContext, Throwable) -> Unit): CoroutineExceptionHandler =
78+
object: AbstractCoroutineContextElement(CoroutineExceptionHandler), CoroutineExceptionHandler {
79+
override fun handleException(context: CoroutineContext, exception: Throwable) =
80+
handler.invoke(context, exception)
81+
}

0 commit comments

Comments
 (0)