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
2b4d9a8e
Commit
2b4d9a8e
authored
Feb 18, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tryNTimes
parent
4bec7d75
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
103 additions
and
0 deletions
+103
-0
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/utils/addSuppressed.kt
...androidMain/kotlin/net/mamoe/mirai/utils/addSuppressed.kt
+16
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/tryNTimes.kt
.../src/commonMain/kotlin/net.mamoe.mirai/utils/tryNTimes.kt
+71
-0
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/addSuppressed.kt
...src/jvmMain/kotlin/net/mamoe/mirai/utils/addSuppressed.kt
+16
-0
No files found.
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/utils/addSuppressed.kt
0 → 100644
View file @
2b4d9a8e
package
net.mamoe.mirai.utils
private
var
isAddSuppressedSupported
:
Boolean
=
true
@MiraiInternalAPI
@Suppress
(
"EXTENSION_SHADOWED_BY_MEMBER"
)
actual
fun
Throwable
.
addSuppressed
(
e
:
Throwable
)
{
if
(!
isAddSuppressedSupported
)
{
return
}
try
{
this
.
addSuppressed
(
e
)
}
catch
(
e
:
Exception
)
{
isAddSuppressedSupported
=
false
}
}
\ No newline at end of file
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/tryNTimes.kt
0 → 100644
View file @
2b4d9a8e
/*
* Copyright 2020 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
package
net.mamoe.mirai.utils
@MiraiInternalAPI
expect
fun
Throwable
.
addSuppressed
(
e
:
Throwable
)
@MiraiInternalAPI
@Suppress
(
"DuplicatedCode"
)
inline
fun
<
R
>
tryNTimes
(
repeat
:
Int
,
block
:
()
->
R
):
R
{
var
lastException
:
Throwable
?
=
null
repeat
(
repeat
)
{
try
{
return
block
()
}
catch
(
e
:
Throwable
)
{
if
(
lastException
==
null
)
{
lastException
=
e
}
lastException
!!
.
addSuppressed
(
e
)
}
}
throw
lastException
!!
}
@MiraiInternalAPI
@Suppress
(
"DuplicatedCode"
)
inline
fun
<
R
>
tryNTimesOrNull
(
repeat
:
Int
,
block
:
()
->
R
):
R
?
{
var
lastException
:
Throwable
?
=
null
repeat
(
repeat
)
{
try
{
return
block
()
}
catch
(
e
:
Throwable
)
{
if
(
lastException
==
null
)
{
lastException
=
e
}
lastException
!!
.
addSuppressed
(
e
)
}
}
return
null
}
@MiraiInternalAPI
@Suppress
(
"DuplicatedCode"
)
inline
fun
<
R
>
tryNTimesOrException
(
repeat
:
Int
,
block
:
()
->
R
):
Throwable
?
{
var
lastException
:
Throwable
?
=
null
repeat
(
repeat
)
{
try
{
block
()
return
null
}
catch
(
e
:
Throwable
)
{
if
(
lastException
==
null
)
{
lastException
=
e
}
lastException
!!
.
addSuppressed
(
e
)
}
}
return
lastException
!!
}
\ No newline at end of file
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/addSuppressed.kt
0 → 100644
View file @
2b4d9a8e
package
net.mamoe.mirai.utils
private
var
isAddSuppressedSupported
:
Boolean
=
true
@MiraiInternalAPI
@Suppress
(
"EXTENSION_SHADOWED_BY_MEMBER"
)
actual
fun
Throwable
.
addSuppressed
(
e
:
Throwable
)
{
if
(!
isAddSuppressedSupported
)
{
return
}
try
{
this
.
addSuppressed
(
e
)
}
catch
(
e
:
Exception
)
{
isAddSuppressedSupported
=
false
}
}
\ 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