diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/tryNTimes.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/tryNTimes.kt index 417d8536a..57f418797 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/tryNTimes.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/tryNTimes.kt @@ -15,12 +15,12 @@ expect fun Throwable.addSuppressed(e: Throwable) @MiraiInternalAPI @Suppress("DuplicatedCode") -inline fun tryNTimes(repeat: Int, block: () -> R): R { +inline fun tryNTimes(repeat: Int, block: (Int) -> R): R { var lastException: Throwable? = null repeat(repeat) { try { - return block() + return block(it) } catch (e: Throwable) { if (lastException == null) { lastException = e @@ -34,12 +34,12 @@ inline fun tryNTimes(repeat: Int, block: () -> R): R { @MiraiInternalAPI @Suppress("DuplicatedCode") -inline fun tryNTimesOrNull(repeat: Int, block: () -> R): R? { +inline fun tryNTimesOrNull(repeat: Int, block: (Int) -> R): R? { var lastException: Throwable? = null repeat(repeat) { try { - return block() + return block(it) } catch (e: Throwable) { if (lastException == null) { lastException = e @@ -53,12 +53,12 @@ inline fun tryNTimesOrNull(repeat: Int, block: () -> R): R? { @MiraiInternalAPI @Suppress("DuplicatedCode") -inline fun tryNTimesOrException(repeat: Int, block: () -> R): Throwable? { +inline fun tryNTimesOrException(repeat: Int, block: (Int) -> R): Throwable? { var lastException: Throwable? = null repeat(repeat) { try { - block() + block(it) return null } catch (e: Throwable) { if (lastException == null) {