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
7e6badb8
Commit
7e6badb8
authored
Apr 05, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use `retryCatching` in place of `tryNTimes`
parent
84869266
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
38 deletions
+23
-38
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt
...moe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt
+5
-6
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/tryNTimes.kt
...nMain/kotlin/net/mamoe/mirai/qqandroid/utils/tryNTimes.kt
+18
-32
No files found.
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt
View file @
7e6badb8
...
@@ -39,8 +39,7 @@ import net.mamoe.mirai.qqandroid.network.protocol.packet.login.WtLogin
...
@@ -39,8 +39,7 @@ import net.mamoe.mirai.qqandroid.network.protocol.packet.login.WtLogin
import
net.mamoe.mirai.qqandroid.utils.PlatformSocket
import
net.mamoe.mirai.qqandroid.utils.PlatformSocket
import
net.mamoe.mirai.qqandroid.utils.io.readPacketExact
import
net.mamoe.mirai.qqandroid.utils.io.readPacketExact
import
net.mamoe.mirai.qqandroid.utils.io.useBytes
import
net.mamoe.mirai.qqandroid.utils.io.useBytes
import
net.mamoe.mirai.qqandroid.utils.tryNTimes
import
net.mamoe.mirai.qqandroid.utils.retryCatching
import
net.mamoe.mirai.qqandroid.utils.tryNTimesOrException
import
net.mamoe.mirai.utils.*
import
net.mamoe.mirai.utils.*
import
kotlin.coroutines.CoroutineContext
import
kotlin.coroutines.CoroutineContext
import
kotlin.jvm.Volatile
import
kotlin.jvm.Volatile
...
@@ -267,7 +266,7 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
...
@@ -267,7 +266,7 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
lateinit
var
loadGroup
:
suspend
()
->
Unit
lateinit
var
loadGroup
:
suspend
()
->
Unit
loadGroup
=
suspend
{
loadGroup
=
suspend
{
tryNTimesOrException
(
3
)
{
retryCatching
(
3
)
{
bot
.
groups
.
delegate
.
addLast
(
bot
.
groups
.
delegate
.
addLast
(
@Suppress
(
"DuplicatedCode"
)
@Suppress
(
"DuplicatedCode"
)
(
GroupImpl
(
(
GroupImpl
(
...
@@ -298,7 +297,7 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
...
@@ -298,7 +297,7 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
)
)
))
))
)
)
}
?.
let
{
}
.
exceptionOrNull
()
?.
let
{
logger
.
error
{
"群${troopNum.groupCode}的列表拉取失败, 一段时间后将会重试"
}
logger
.
error
{
"群${troopNum.groupCode}的列表拉取失败, 一段时间后将会重试"
}
logger
.
error
(
it
)
logger
.
error
(
it
)
this
@QQAndroidBotNetworkHandler
.
launch
{
this
@QQAndroidBotNetworkHandler
.
launch
{
...
@@ -618,7 +617,7 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
...
@@ -618,7 +617,7 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
packetListeners
.
remove
(
handler
)
packetListeners
.
remove
(
handler
)
}
}
}
else
this
.
delegate
.
useBytes
{
data
,
length
->
}
else
this
.
delegate
.
useBytes
{
data
,
length
->
return
tryNTimes
(
retry
+
1
)
{
return
retryCatching
(
retry
+
1
)
{
val
handler
=
PacketListener
(
commandName
=
commandName
,
sequenceId
=
sequenceId
)
val
handler
=
PacketListener
(
commandName
=
commandName
,
sequenceId
=
sequenceId
)
packetListeners
.
addLast
(
handler
)
packetListeners
.
addLast
(
handler
)
try
{
try
{
...
@@ -626,7 +625,7 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
...
@@ -626,7 +625,7 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
}
finally
{
}
finally
{
packetListeners
.
remove
(
handler
)
packetListeners
.
remove
(
handler
)
}
}
}
}
.
getOrThrow
()
}
}
}
}
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/tryNTimes.kt
View file @
7e6badb8
...
@@ -13,46 +13,32 @@
...
@@ -13,46 +13,32 @@
package
net.mamoe.mirai.qqandroid.utils
package
net.mamoe.mirai.qqandroid.utils
import
net.mamoe.mirai.utils.MiraiInternalAPI
import
kotlin.contracts.ExperimentalContracts
import
kotlin.contracts.InvocationKind
import
kotlin.contracts.contract
import
kotlin.jvm.JvmMultifileClass
import
kotlin.jvm.JvmMultifileClass
import
kotlin.jvm.JvmName
import
kotlin.jvm.JvmName
@PublishedApi
@PublishedApi
internal
expect
fun
Throwable
.
addSuppressedMirai
(
e
:
Throwable
)
internal
expect
fun
Throwable
.
addSuppressedMirai
(
e
:
Throwable
)
@MiraiInternalAPI
@OptIn
(
ExperimentalContracts
::
class
)
@Suppress
(
"DuplicatedCode"
)
@Suppress
(
"INVISIBLE_MEMBER"
,
"INVISIBLE_REFERENCE"
,
"RESULT_CLASS_IN_RETURN_TYPE"
)
internal
inline
fun
<
R
>
tryNTimes
(
repeat
:
Int
,
block
:
(
Int
)
->
R
):
R
{
@
kotlin
.
internal
.
InlineOnly
var
lastException
:
Throwable
?
=
null
internal
inline
fun
<
R
>
retryCatching
(
n
:
Int
,
block
:
()
->
R
):
Result
<
R
>
{
contract
{
repeat
(
repeat
)
{
callsInPlace
(
block
,
InvocationKind
.
AT_LEAST_ONCE
)
try
{
return
block
(
it
)
}
catch
(
e
:
Throwable
)
{
if
(
lastException
==
null
)
{
lastException
=
e
}
else
lastException
!!
.
addSuppressedMirai
(
e
)
}
}
}
require
(
n
>=
0
)
{
"param n for retryCatching must not be negative"
}
throw
lastException
!!
var
exception
:
Throwable
?
=
null
}
repeat
(
n
)
{
@MiraiInternalAPI
@Suppress
(
"DuplicatedCode"
)
inline
fun
<
R
>
tryNTimesOrException
(
repeat
:
Int
,
block
:
(
Int
)
->
R
):
Throwable
?
{
var
lastException
:
Throwable
?
=
null
repeat
(
repeat
)
{
try
{
try
{
block
(
it
)
return
Result
.
success
(
block
())
return
null
}
catch
(
e
:
Throwable
)
{
}
catch
(
e
:
Throwable
)
{
if
(
lastException
==
null
)
{
exception
?.
addSuppressedMirai
(
e
)
lastException
=
e
exception
=
e
}
else
lastException
!!
.
addSuppressedMirai
(
e
)
}
}
}
}
return
Result
.
failure
(
exception
!!
)
return
lastException
!!
}
}
\ No newline at end of file
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