com.fireflysource.common.concurrent.CompletableFutureExtension.kt Maven / Gradle / Ivy
The newest version!
package com.fireflysource.common.concurrent
import com.fireflysource.common.sys.Result
import java.util.concurrent.CompletableFuture
import java.util.concurrent.CompletionStage
inline fun CompletionStage.exceptionallyCompose(crossinline block: (Throwable) -> CompletionStage): CompletableFuture {
return CompletableFutures.exceptionallyCompose(this) { block(it) }.toCompletableFuture()
}
inline fun CompletionStage.exceptionallyAccept(crossinline block: (Throwable) -> Unit): CompletableFuture {
return this.exceptionally {
block(it)
null
}.thenCompose { Result.DONE }.toCompletableFuture()
}
inline fun CompletionStage.doFinally(crossinline block: (T?, Throwable?) -> CompletableFuture): CompletableFuture {
return CompletableFutures.doFinally(this) { value, throwable -> block(value, throwable) }
}