Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
23273718
Commit
23273718
authored
May 16, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve docs
parent
3d06219c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
4 deletions
+27
-4
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/event/JvmMethodListeners.kt
...vmMain/kotlin/net/mamoe/mirai/event/JvmMethodListeners.kt
+27
-4
No files found.
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/event/JvmMethodListeners.kt
View file @
23273718
...
...
@@ -34,7 +34,7 @@ import kotlin.reflect.jvm.kotlinFunction
*
* 所有 Kotlin 非 `suspend` 的函数都将会在 [Dispatchers.IO] 中调用
*
*
所有
支持的函数类型:
* 支持的函数类型:
* ```
* suspend fun T.onEvent(T)
* suspend fun T.onEvent(T): ListeningStatus
...
...
@@ -50,9 +50,10 @@ import kotlin.reflect.jvm.kotlinFunction
* fun T.onEvent(): ListeningStatus
* ```
*
* 使用示例:
* Kotlin 使用示例:
* - 独立 [CoroutineScope] 和 [ListenerHost]
* ```
* object MyEvents : ListenerHost
, CoroutineScope
{
* object MyEvents : ListenerHost {
* override val coroutineContext = SupervisorJob()
*
* @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
()
*
```
*
*
*
###
Java
方法
*
所有
Java
方法都会在
[
Dispatchers
.
IO
]
中调用
.
*
...
...
@@ -73,7 +93,8 @@ import kotlin.reflect.jvm.kotlinFunction
*
ListeningStatus
onEvent
(
T
)
*
```
*
* 使用示例:
*
*
Java
使用示例
:
*
```
*
public
class
MyEventHandlers
extends
SimpleListenerHost
{
*
@Override
...
...
@@ -123,6 +144,8 @@ interface ListenerHost
/**
* 携带一个异常处理器的 [ListenerHost].
* @see ListenerHost 查看更多信息
* @see EventHandler 查看更多信息
*/
abstract
class
SimpleListenerHost
@JvmOverloads
constructor
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
)
:
ListenerHost
,
CoroutineScope
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment