mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-05 07:30:09 +08:00
Improve docs
This commit is contained in:
parent
3d06219c67
commit
23273718fe
@ -34,7 +34,7 @@ import kotlin.reflect.jvm.kotlinFunction
|
|||||||
*
|
*
|
||||||
* 所有 Kotlin 非 `suspend` 的函数都将会在 [Dispatchers.IO] 中调用
|
* 所有 Kotlin 非 `suspend` 的函数都将会在 [Dispatchers.IO] 中调用
|
||||||
*
|
*
|
||||||
* 所有支持的函数类型:
|
* 支持的函数类型:
|
||||||
* ```
|
* ```
|
||||||
* suspend fun T.onEvent(T)
|
* suspend fun T.onEvent(T)
|
||||||
* suspend fun T.onEvent(T): ListeningStatus
|
* suspend fun T.onEvent(T): ListeningStatus
|
||||||
@ -50,9 +50,10 @@ import kotlin.reflect.jvm.kotlinFunction
|
|||||||
* fun T.onEvent(): ListeningStatus
|
* fun T.onEvent(): ListeningStatus
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* 使用示例:
|
* Kotlin 使用示例:
|
||||||
|
* - 独立 [CoroutineScope] 和 [ListenerHost]
|
||||||
* ```
|
* ```
|
||||||
* object MyEvents : ListenerHost, CoroutineScope {
|
* object MyEvents : ListenerHost {
|
||||||
* override val coroutineContext = SupervisorJob()
|
* override val coroutineContext = SupervisorJob()
|
||||||
*
|
*
|
||||||
* @EventHandler
|
* @EventHandler
|
||||||
@ -61,9 +62,28 @@ import kotlin.reflect.jvm.kotlinFunction
|
|||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
|
* myCoroutineScope.registerEvents(MyEvents)
|
||||||
|
* ```
|
||||||
|
* `onMessage` 抛出的异常将会交给 `myCoroutineScope` 处理
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* - 合并 [CoroutineScope] 和 [ListenerHost]: 使用 [SimpleListenerHost]
|
||||||
|
* ```
|
||||||
|
* object MyEvents : SimpleListenerHost( /* override coroutineContext here */ ) {
|
||||||
|
* override fun handleException(context: CoroutineContext, exception: Throwable) {
|
||||||
|
* // 处理 onMessage 中未捕获的异常
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* @EventHandler
|
||||||
|
* suspend fun MessageEvent.onMessage() {
|
||||||
|
* reply("received")
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
*
|
||||||
* MyEvents.registerEvents()
|
* MyEvents.registerEvents()
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
|
*
|
||||||
* ### Java 方法
|
* ### Java 方法
|
||||||
* 所有 Java 方法都会在 [Dispatchers.IO] 中调用.
|
* 所有 Java 方法都会在 [Dispatchers.IO] 中调用.
|
||||||
*
|
*
|
||||||
@ -73,7 +93,8 @@ import kotlin.reflect.jvm.kotlinFunction
|
|||||||
* ListeningStatus onEvent(T)
|
* ListeningStatus onEvent(T)
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* 使用示例:
|
*
|
||||||
|
* Java 使用示例:
|
||||||
* ```
|
* ```
|
||||||
* public class MyEventHandlers extends SimpleListenerHost {
|
* public class MyEventHandlers extends SimpleListenerHost {
|
||||||
* @Override
|
* @Override
|
||||||
@ -123,6 +144,8 @@ interface ListenerHost
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 携带一个异常处理器的 [ListenerHost].
|
* 携带一个异常处理器的 [ListenerHost].
|
||||||
|
* @see ListenerHost 查看更多信息
|
||||||
|
* @see EventHandler 查看更多信息
|
||||||
*/
|
*/
|
||||||
abstract class SimpleListenerHost
|
abstract class SimpleListenerHost
|
||||||
@JvmOverloads constructor(coroutineContext: CoroutineContext = EmptyCoroutineContext) : ListenerHost, CoroutineScope {
|
@JvmOverloads constructor(coroutineContext: CoroutineContext = EmptyCoroutineContext) : ListenerHost, CoroutineScope {
|
||||||
|
Loading…
Reference in New Issue
Block a user