Add Java-friendly EventChannel.exceptionHandler API, close #1953

This commit is contained in:
Him188 2022-06-08 21:42:20 +01:00
parent bcaf9b5060
commit 1a2241b8b2
No known key found for this signature in database
GPG Key ID: BA439CDDCF652375
3 changed files with 13 additions and 0 deletions

View File

@ -1737,6 +1737,7 @@ public abstract class net/mamoe/mirai/event/EventChannel {
public static synthetic fun asChannel$default (Lnet/mamoe/mirai/event/EventChannel;ILkotlin/coroutines/CoroutineContext;Lnet/mamoe/mirai/event/ConcurrencyKind;Lnet/mamoe/mirai/event/EventPriority;ILjava/lang/Object;)Lkotlinx/coroutines/channels/Channel;
public abstract fun asFlow ()Lkotlinx/coroutines/flow/Flow;
public abstract fun context ([Lkotlin/coroutines/CoroutineContext;)Lnet/mamoe/mirai/event/EventChannel;
public final fun exceptionHandler (Ljava/util/function/Consumer;)Lnet/mamoe/mirai/event/EventChannel;
public final fun exceptionHandler (Lkotlin/jvm/functions/Function1;)Lnet/mamoe/mirai/event/EventChannel;
public final fun exceptionHandler (Lkotlinx/coroutines/CoroutineExceptionHandler;)Lnet/mamoe/mirai/event/EventChannel;
public final fun filter (Lkotlin/jvm/functions/Function1;)Lnet/mamoe/mirai/event/EventChannel;

View File

@ -1737,6 +1737,7 @@ public abstract class net/mamoe/mirai/event/EventChannel {
public static synthetic fun asChannel$default (Lnet/mamoe/mirai/event/EventChannel;ILkotlin/coroutines/CoroutineContext;Lnet/mamoe/mirai/event/ConcurrencyKind;Lnet/mamoe/mirai/event/EventPriority;ILjava/lang/Object;)Lkotlinx/coroutines/channels/Channel;
public abstract fun asFlow ()Lkotlinx/coroutines/flow/Flow;
public abstract fun context ([Lkotlin/coroutines/CoroutineContext;)Lnet/mamoe/mirai/event/EventChannel;
public final fun exceptionHandler (Ljava/util/function/Consumer;)Lnet/mamoe/mirai/event/EventChannel;
public final fun exceptionHandler (Lkotlin/jvm/functions/Function1;)Lnet/mamoe/mirai/event/EventChannel;
public final fun exceptionHandler (Lkotlinx/coroutines/CoroutineExceptionHandler;)Lnet/mamoe/mirai/event/EventChannel;
public final fun filter (Lkotlin/jvm/functions/Function1;)Lnet/mamoe/mirai/event/EventChannel;

View File

@ -314,6 +314,17 @@ public abstract class EventChannel<out BaseEvent : Event> @MiraiInternalApi publ
})
}
/**
* 创建一个新的 [EventChannel], [EventChannel] 包含 [`this.coroutineContext`][defaultCoroutineContext] 和添加的 [coroutineExceptionHandler]
* @see context
* @since 2.12
*/
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@kotlin.internal.LowPriorityInOverloadResolution
public fun exceptionHandler(coroutineExceptionHandler: Consumer<Throwable>): EventChannel<BaseEvent> {
return exceptionHandler { coroutineExceptionHandler.accept(it) }
}
/**
* [coroutineScope] 作为这个 [EventChannel] 的父作用域.
*