org.whispersystems.signalservice.internal.util.CompletableFutureExtensions.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of signal-service-java Show documentation
Show all versions of signal-service-java Show documentation
Signal Service communication library for Java, unofficial fork
/*
* Copyright 2024 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/
package org.whispersystems.signalservice.internal.util
import org.signal.libsignal.internal.CompletableFuture
/**
* A Kotlin friendly adapter for [org.signal.libsignal.internal.CompletableFuture.whenComplete]
* taking two callbacks ([onSuccess] and [onFailure]) instead of a [java.util.function.BiConsumer].
*/
fun CompletableFuture.whenComplete(
onSuccess: ((T?) -> Unit),
onFailure: ((Throwable) -> Unit)
): CompletableFuture {
return this.whenComplete { value, throwable ->
if (throwable != null) {
onFailure(throwable)
} else {
onSuccess(value)
}
}
}