Commit 23273718 authored by Him188's avatar Him188

Improve docs

parent 3d06219c
...@@ -34,7 +34,7 @@ import kotlin.reflect.jvm.kotlinFunction ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment