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
3255e330
Commit
3255e330
authored
May 06, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement event priority for selectMessages
parent
42ceb380
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
12 deletions
+21
-12
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/select.kt
...ore/src/commonMain/kotlin/net.mamoe.mirai/event/select.kt
+21
-12
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/select.kt
View file @
3255e330
...
@@ -62,8 +62,9 @@ import kotlin.jvm.JvmSynthetic
...
@@ -62,8 +62,9 @@ import kotlin.jvm.JvmSynthetic
suspend
inline
fun
<
reified
T
:
MessageEvent
>
T
.
whileSelectMessages
(
suspend
inline
fun
<
reified
T
:
MessageEvent
>
T
.
whileSelectMessages
(
timeoutMillis
:
Long
=
-
1
,
timeoutMillis
:
Long
=
-
1
,
filterContext
:
Boolean
=
true
,
filterContext
:
Boolean
=
true
,
priority
:
Listener
.
EventPriority
=
Listener
.
EventPriority
.
MONITOR
,
crossinline
selectBuilder
:
@MessageDsl
MessageSelectBuilder
<
T
,
Boolean
>.()
->
Unit
crossinline
selectBuilder
:
@MessageDsl
MessageSelectBuilder
<
T
,
Boolean
>.()
->
Unit
)
=
whileSelectMessagesImpl
(
timeoutMillis
,
filterContext
,
selectBuilder
)
)
=
whileSelectMessagesImpl
(
timeoutMillis
,
filterContext
,
priority
,
selectBuilder
)
/**
/**
* [selectMessages] 的 [Unit] 返回值捷径 (由于 Kotlin 无法推断 [Unit] 类型)
* [selectMessages] 的 [Unit] 返回值捷径 (由于 Kotlin 无法推断 [Unit] 类型)
...
@@ -74,8 +75,9 @@ suspend inline fun <reified T : MessageEvent> T.whileSelectMessages(
...
@@ -74,8 +75,9 @@ suspend inline fun <reified T : MessageEvent> T.whileSelectMessages(
suspend
inline
fun
<
reified
T
:
MessageEvent
>
T
.
selectMessagesUnit
(
suspend
inline
fun
<
reified
T
:
MessageEvent
>
T
.
selectMessagesUnit
(
timeoutMillis
:
Long
=
-
1
,
timeoutMillis
:
Long
=
-
1
,
filterContext
:
Boolean
=
true
,
filterContext
:
Boolean
=
true
,
priority
:
Listener
.
EventPriority
=
Listener
.
EventPriority
.
MONITOR
,
crossinline
selectBuilder
:
@MessageDsl
MessageSelectBuilderUnit
<
T
,
Unit
>.()
->
Unit
crossinline
selectBuilder
:
@MessageDsl
MessageSelectBuilderUnit
<
T
,
Unit
>.()
->
Unit
)
=
selectMessagesImpl
(
timeoutMillis
,
true
,
filterContext
,
selectBuilder
)
)
=
selectMessagesImpl
(
timeoutMillis
,
true
,
filterContext
,
priority
,
selectBuilder
)
/**
/**
...
@@ -103,10 +105,14 @@ suspend inline fun <reified T : MessageEvent> T.selectMessagesUnit(
...
@@ -103,10 +105,14 @@ suspend inline fun <reified T : MessageEvent> T.selectMessagesUnit(
suspend
inline
fun
<
reified
T
:
MessageEvent
,
R
>
T
.
selectMessages
(
suspend
inline
fun
<
reified
T
:
MessageEvent
,
R
>
T
.
selectMessages
(
timeoutMillis
:
Long
=
-
1
,
timeoutMillis
:
Long
=
-
1
,
filterContext
:
Boolean
=
true
,
filterContext
:
Boolean
=
true
,
priority
:
Listener
.
EventPriority
=
Listener
.
EventPriority
.
MONITOR
,
// @BuilderInference
// @BuilderInference
crossinline
selectBuilder
:
@MessageDsl
MessageSelectBuilder
<
T
,
R
>.()
->
Unit
crossinline
selectBuilder
:
@MessageDsl
MessageSelectBuilder
<
T
,
R
>.()
->
Unit
):
R
=
):
R
=
selectMessagesImpl
(
timeoutMillis
,
false
,
filterContext
)
{
selectBuilder
.
invoke
(
this
as
MessageSelectBuilder
<
T
,
R
>)
}
selectMessagesImpl
(
timeoutMillis
,
false
,
filterContext
,
priority
)
{
selectBuilder
.
invoke
(
this
as
MessageSelectBuilder
<
T
,
R
>)
}
/**
/**
* [selectMessages] 时的 DSL 构建器.
* [selectMessages] 时的 DSL 构建器.
...
@@ -434,16 +440,11 @@ inline class MessageSelectionTimeoutChecker internal constructor(val timeoutMill
...
@@ -434,16 +440,11 @@ inline class MessageSelectionTimeoutChecker internal constructor(val timeoutMill
class
MessageSelectionTimeoutException
:
RuntimeException
()
class
MessageSelectionTimeoutException
:
RuntimeException
()
/////////////////////////
/////////////////////////
//// implementations ////
//// implementations ////
/////////////////////////
/////////////////////////
@JvmSynthetic
@JvmSynthetic
@PublishedApi
@PublishedApi
internal
suspend
inline
fun
<
R
>
withSilentTimeoutOrCoroutineScope
(
internal
suspend
inline
fun
<
R
>
withSilentTimeoutOrCoroutineScope
(
...
@@ -478,6 +479,7 @@ internal suspend inline fun <reified T : MessageEvent, R> T.selectMessagesImpl(
...
@@ -478,6 +479,7 @@ internal suspend inline fun <reified T : MessageEvent, R> T.selectMessagesImpl(
timeoutMillis
:
Long
=
-
1
,
timeoutMillis
:
Long
=
-
1
,
isUnit
:
Boolean
,
isUnit
:
Boolean
,
filterContext
:
Boolean
=
true
,
filterContext
:
Boolean
=
true
,
priority
:
Listener
.
EventPriority
,
@BuilderInference
@BuilderInference
crossinline
selectBuilder
:
@MessageDsl
MessageSelectBuilderUnit
<
T
,
R
>.()
->
Unit
crossinline
selectBuilder
:
@MessageDsl
MessageSelectBuilderUnit
<
T
,
R
>.()
->
Unit
):
R
=
withSilentTimeoutOrCoroutineScope
(
timeoutMillis
)
{
):
R
=
withSilentTimeoutOrCoroutineScope
(
timeoutMillis
)
{
...
@@ -526,7 +528,10 @@ internal suspend inline fun <reified T : MessageEvent, R> T.selectMessagesImpl(
...
@@ -526,7 +528,10 @@ internal suspend inline fun <reified T : MessageEvent, R> T.selectMessagesImpl(
// we don't have any way to reduce duplication yet,
// we don't have any way to reduce duplication yet,
// until local functions are supported in inline functions
// until local functions are supported in inline functions
@Suppress
(
"DuplicatedCode"
)
val
subscribeAlways
=
subscribeAlways
<
T
>
{
event
->
@Suppress
(
"DuplicatedCode"
)
val
subscribeAlways
=
subscribeAlways
<
T
>(
concurrency
=
Listener
.
ConcurrencyKind
.
LOCKED
,
priority
=
priority
)
{
event
->
if
(
filterContext
&&
!
this
.
isContextIdenticalWith
(
this
@
selectMessagesImpl
))
if
(
filterContext
&&
!
this
.
isContextIdenticalWith
(
this
@
selectMessagesImpl
))
return
@
subscribeAlways
return
@
subscribeAlways
...
@@ -574,8 +579,9 @@ internal suspend inline fun <reified T : MessageEvent, R> T.selectMessagesImpl(
...
@@ -574,8 +579,9 @@ internal suspend inline fun <reified T : MessageEvent, R> T.selectMessagesImpl(
@Suppress
(
"unused"
)
@Suppress
(
"unused"
)
@PublishedApi
@PublishedApi
internal
suspend
inline
fun
<
reified
T
:
MessageEvent
>
T
.
whileSelectMessagesImpl
(
internal
suspend
inline
fun
<
reified
T
:
MessageEvent
>
T
.
whileSelectMessagesImpl
(
timeoutMillis
:
Long
=
-
1
,
timeoutMillis
:
Long
,
filterContext
:
Boolean
=
true
,
filterContext
:
Boolean
,
priority
:
Listener
.
EventPriority
,
crossinline
selectBuilder
:
@MessageDsl
MessageSelectBuilder
<
T
,
Boolean
>.()
->
Unit
crossinline
selectBuilder
:
@MessageDsl
MessageSelectBuilder
<
T
,
Boolean
>.()
->
Unit
)
=
withSilentTimeoutOrCoroutineScope
(
timeoutMillis
)
{
)
=
withSilentTimeoutOrCoroutineScope
(
timeoutMillis
)
{
var
deferred
:
CompletableDeferred
<
Boolean
>?
=
CompletableDeferred
()
var
deferred
:
CompletableDeferred
<
Boolean
>?
=
CompletableDeferred
()
...
@@ -604,7 +610,10 @@ internal suspend inline fun <reified T : MessageEvent> T.whileSelectMessagesImpl
...
@@ -604,7 +610,10 @@ internal suspend inline fun <reified T : MessageEvent> T.whileSelectMessagesImpl
}.
apply
(
selectBuilder
)
}.
apply
(
selectBuilder
)
// ensure atomic completing
// ensure atomic completing
val
subscribeAlways
=
subscribeAlways
<
T
>(
concurrency
=
Listener
.
ConcurrencyKind
.
LOCKED
)
{
event
->
val
subscribeAlways
=
subscribeAlways
<
T
>(
concurrency
=
Listener
.
ConcurrencyKind
.
LOCKED
,
priority
=
priority
)
{
event
->
if
(
filterContext
&&
!
this
.
isContextIdenticalWith
(
this
@
whileSelectMessagesImpl
))
if
(
filterContext
&&
!
this
.
isContextIdenticalWith
(
this
@
whileSelectMessagesImpl
))
return
@
subscribeAlways
return
@
subscribeAlways
...
...
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