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
cd6c8183
Commit
cd6c8183
authored
Dec 02, 2019
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduce suspend fun calls
parent
4587f7ae
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
25 deletions
+26
-25
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/internal/InternalEventListeners.kt
.../net.mamoe.mirai/event/internal/InternalEventListeners.kt
+26
-25
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/internal/InternalEventListeners.kt
View file @
cd6c8183
...
...
@@ -188,31 +188,6 @@ internal object EventListenerManger {
internal
suspend
fun
<
E
:
Subscribable
>
E
.
broadcastInternal
():
E
{
if
(
EventDisabled
)
return
this
suspend
fun
callListeners
(
listeners
:
EventListeners
<
in
E
>)
{
suspend
fun
callAndRemoveIfRequired
()
=
listeners
.
inlinedRemoveIf
{
if
(
it
.
lock
.
tryLock
())
{
try
{
it
.
onEvent
(
this
)
==
ListeningStatus
.
STOPPED
}
finally
{
it
.
lock
.
unlock
()
}
}
else
false
}
//自己持有, 则是在一个事件中
if
(
listeners
.
mainMutex
.
holdsLock
(
listeners
))
{
callAndRemoveIfRequired
()
}
else
{
while
(!
listeners
.
mainMutex
.
tryLock
(
listeners
))
{
delay
(
10
)
}
try
{
callAndRemoveIfRequired
()
}
finally
{
listeners
.
mainMutex
.
unlock
(
listeners
)
}
}
}
callListeners
(
this
::
class
.
listeners
())
...
...
@@ -220,6 +195,32 @@ internal suspend fun <E : Subscribable> E.broadcastInternal(): E {
return
this
}
private
suspend
inline
fun
<
E
:
Subscribable
>
E
.
callListeners
(
listeners
:
EventListeners
<
in
E
>)
{
//自己持有, 则是在一个事件中
if
(
listeners
.
mainMutex
.
holdsLock
(
listeners
))
{
callAndRemoveIfRequired
(
listeners
)
}
else
{
while
(!
listeners
.
mainMutex
.
tryLock
(
listeners
))
{
delay
(
10
)
}
try
{
callAndRemoveIfRequired
(
listeners
)
}
finally
{
listeners
.
mainMutex
.
unlock
(
listeners
)
}
}
}
private
suspend
inline
fun
<
E
:
Subscribable
>
E
.
callAndRemoveIfRequired
(
listeners
:
EventListeners
<
in
E
>)
=
listeners
.
inlinedRemoveIf
{
if
(
it
.
lock
.
tryLock
())
{
try
{
it
.
onEvent
(
this
)
==
ListeningStatus
.
STOPPED
}
finally
{
it
.
lock
.
unlock
()
}
}
else
false
}
/**
* apply [block] to all the [EventListeners] in [clazz]'s superclasses
*/
...
...
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