dev.restate.sdk.common.function.ThrowingBiConsumer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sdk-common Show documentation
Show all versions of sdk-common Show documentation
Common interfaces of the Restate SDK
The newest version!
// Copyright (c) 2023 - Restate Software, Inc., Restate GmbH
//
// This file is part of the Restate Java SDK,
// which is released under the MIT license.
//
// You can find a copy of the license in file LICENSE in the root
// directory of this repository or package, or at
// https://github.com/restatedev/sdk-java/blob/main/LICENSE
package dev.restate.sdk.common.function;
import java.util.function.BiConsumer;
/** Like {@link BiConsumer} but can throw checked exceptions. */
@FunctionalInterface
public interface ThrowingBiConsumer {
void accept(T var1, U var2) throws Throwable;
static BiConsumer wrap(ThrowingBiConsumer fn) {
return fn.asBiConsumer();
}
default BiConsumer asBiConsumer() {
return (t, u) -> {
try {
this.accept(t, u);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
} catch (Throwable e) {
// Make sure we propagate java.lang.Error
sneakyThrow(e);
}
};
}
@SuppressWarnings("unchecked")
private static void sneakyThrow(Throwable e) throws E {
throw (E) e;
}
}