All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fireflysource.common.concurrent.CompletableFutureExtension.kt Maven / Gradle / Ivy

There is a newer version: 5.0.2
Show 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) }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy