Commit 4f7b266e authored by Him188's avatar Him188

Add tryCount param to lambda

parent 3b7a9b6d
...@@ -15,12 +15,12 @@ expect fun Throwable.addSuppressed(e: Throwable) ...@@ -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 { ...@@ -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? { ...@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment