本文整理了Java中io.vavr.control.Try.peek()
方法的一些代码示例,展示了Try.peek()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Try.peek()
方法的具体详情如下:
包路径:io.vavr.control.Try
类名称:Try
方法名:peek
[英]Applies the action to the value of a Success or does nothing in the case of a Failure.
[中]
代码示例来源:origin: RoboZonky/robozonky
CompletableFuture<Void> refreshIfNotAlreadyRefreshing(final CompletableFuture<Void> old) {
if (old == null || old.isDone()) {
logger.trace("Starting async reload.");
final Runnable asyncOperation = () -> Try.ofSupplier(() -> getOperation().apply(value.get()))
.peek(v -> processRetrievedValue(v, value::set)) // set the value on success
.getOrElseGet(t -> {
logger.warn("Async reload failed, operating with stale value.", t);
return null;
});
return CompletableFuture.runAsync(asyncOperation, Scheduler.inBackground().getExecutor());
} else {
logger.trace("Reload already in progress on {} with {}.", this, old);
return old;
}
}
代码示例来源:origin: com.github.robozonky/robozonky-common
CompletableFuture<Void> refresh(final CompletableFuture<Void> old) {
if (old == null || old.isDone()) {
logger.trace("Starting async reload.");
final Runnable asyncOperation = () -> Try.ofSupplier(getOperation())
.peek(v -> processRetrievedValue(v, value::set)) // set the value on success
.getOrElseGet(t -> {
logger.warn("Async reload failed, operating with stale value.", t);
return null;
});
return CompletableFuture.runAsync(asyncOperation, Scheduler.inBackground().getExecutor());
} else {
logger.trace("Reload already in progress on {} with {}.", this, old);
return old;
}
}
代码示例来源:origin: com.github.robozonky/robozonky-common
@Override
public synchronized Either<Throwable, T> get() {
if (!needsReload()) {
logger.trace("Not reloading {}.", this);
return Either.right(value.get());
}
logger.trace("Reloading {}.", this);
return Try.ofSupplier(getOperation())
.peek(v -> processRetrievedValue(v, value::set))
.toEither();
}
}
代码示例来源:origin: RoboZonky/robozonky
@Override
public Either<Throwable, T> get() {
if (needsReload()) { // double-checked locking to make sure the reload only happens once
synchronized (this) {
if (needsReload()) {
logger.trace("Reloading {}.", this);
return Try.ofSupplier(() -> getOperation().apply(value.get()))
.peek(v -> processRetrievedValue(v, value::set))
.toEither();
}
// otherwise fall through to retrieve the value
}
}
logger.trace("Not reloading {}.", this);
return Either.right(value.get());
}
代码示例来源:origin: com.github.robozonky/robozonky-common
@Override
public synchronized Either<Throwable, T> get() {
if (value.get() == null) { // force value retrieval and wait for it
logger.debug("Fetching initial value synchronously on {}.", this);
return Try.ofSupplier(getOperation())
.peek(v -> processRetrievedValue(v, value::set))
.toEither();
}
if (!needsReload()) { // return old value
logger.trace("Not reloading {}.", this);
return Either.right(value.get());
}
// trigger retrieval but return existing value
final CompletableFuture<Void> currentFuture = future.getAndUpdate(this::refresh);
logger.debug("Retrieved potentially stale value on {}, while {}.", this, currentFuture);
return Either.right(value.get());
}
}
代码示例来源:origin: RoboZonky/robozonky
@Override
public Either<Throwable, T> get() {
if (!hasValue()) { // force value retrieval and wait for it
synchronized (this) {
if (!hasValue()) { // double-checked locking to make sure the value is only ever loaded once
logger.debug("Fetching initial value synchronously on {}.", this);
return Try.ofSupplier(() -> getOperation().apply(null))
.peek(v -> processRetrievedValue(v, value::set))
.toEither();
}
// otherwise fall through to retrieve the current value
}
}
if (needsReload()) { // trigger value retrieval on the background
synchronized (this) {
final CompletableFuture<Void> currentFuture = future.getAndUpdate(this::refreshIfNotAlreadyRefreshing);
logger.debug("Retrieved potentially stale value on {}, while {}.", this, currentFuture);
}
}
// return the current value
return Either.right(value.get());
}
代码示例来源:origin: Tristan971/Lyrebird
/**
* Pre-formats a status' text content.
*
* @param status The status whose content we have to format
*/
private void loadTextIntoTextFlow(final Status status) {
tweetContent.getChildren().clear();
final FxmlLoadResult<Pane, TweetContentPaneController> result = easyFxml.loadNode(
FxComponent.TWEET_CONTENT_PANE,
Pane.class,
TweetContentPaneController.class
);
result.afterControllerLoaded(tcpc -> tcpc.setStatusProp(status))
.getNode()
.peek(pane -> VBox.setVgrow(pane, Priority.ALWAYS))
.recover(ExceptionHandler::fromThrowable)
.andThen(tweetContent.getChildren()::add);
}
内容来源于网络,如有侵权,请联系作者删除!