mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-09 18:00:33 +08:00
Add tryCount param to lambda
This commit is contained in:
parent
3b7a9b6d42
commit
4f7b266e03
@ -15,12 +15,12 @@ expect fun Throwable.addSuppressed(e: Throwable)
|
|||||||
|
|
||||||
@MiraiInternalAPI
|
@MiraiInternalAPI
|
||||||
@Suppress("DuplicatedCode")
|
@Suppress("DuplicatedCode")
|
||||||
inline fun <R> tryNTimes(repeat: Int, block: () -> R): R {
|
inline fun <R> tryNTimes(repeat: Int, block: (Int) -> R): R {
|
||||||
var lastException: Throwable? = null
|
var lastException: Throwable? = null
|
||||||
|
|
||||||
repeat(repeat) {
|
repeat(repeat) {
|
||||||
try {
|
try {
|
||||||
return block()
|
return block(it)
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
if (lastException == null) {
|
if (lastException == null) {
|
||||||
lastException = e
|
lastException = e
|
||||||
@ -34,12 +34,12 @@ inline fun <R> tryNTimes(repeat: Int, block: () -> R): R {
|
|||||||
|
|
||||||
@MiraiInternalAPI
|
@MiraiInternalAPI
|
||||||
@Suppress("DuplicatedCode")
|
@Suppress("DuplicatedCode")
|
||||||
inline fun <R> tryNTimesOrNull(repeat: Int, block: () -> R): R? {
|
inline fun <R> tryNTimesOrNull(repeat: Int, block: (Int) -> R): R? {
|
||||||
var lastException: Throwable? = null
|
var lastException: Throwable? = null
|
||||||
|
|
||||||
repeat(repeat) {
|
repeat(repeat) {
|
||||||
try {
|
try {
|
||||||
return block()
|
return block(it)
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
if (lastException == null) {
|
if (lastException == null) {
|
||||||
lastException = e
|
lastException = e
|
||||||
@ -53,12 +53,12 @@ inline fun <R> tryNTimesOrNull(repeat: Int, block: () -> R): R? {
|
|||||||
|
|
||||||
@MiraiInternalAPI
|
@MiraiInternalAPI
|
||||||
@Suppress("DuplicatedCode")
|
@Suppress("DuplicatedCode")
|
||||||
inline fun <R> tryNTimesOrException(repeat: Int, block: () -> R): Throwable? {
|
inline fun <R> tryNTimesOrException(repeat: Int, block: (Int) -> R): Throwable? {
|
||||||
var lastException: Throwable? = null
|
var lastException: Throwable? = null
|
||||||
|
|
||||||
repeat(repeat) {
|
repeat(repeat) {
|
||||||
try {
|
try {
|
||||||
block()
|
block(it)
|
||||||
return null
|
return null
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
if (lastException == null) {
|
if (lastException == null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user