package io.vertx.core.impl.future;
import io.vertx.core.impl.ContextInternal;
import java.util.function.Function;
class OtherwiseTransformation<T> extends Transformation<T> implements Listener<T> {
private final Function<Throwable, T> mapper;
OtherwiseTransformation(ContextInternal context, Function<Throwable, T> mapper) {
super(context);
this.mapper = mapper;
}
@Override
public void onSuccess(T value) {
tryComplete(value);
}
@Override
public void onFailure(Throwable failure) {
T result;
try {
result = mapper.apply(failure);
} catch (Throwable e) {
tryFail(e);
return;
}
tryComplete(result);
}
}