use of ratpack.exec.internal.ResultBackedExecResult in project ratpack by ratpack.
the class DefaultExecHarness method yield.
@Override
public <T> ExecResult<T> yield(Action<? super RegistrySpec> registry, final Function<? super Execution, ? extends Promise<T>> func) throws Exception {
AtomicReference<ExecResult<T>> reference = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
controller.fork().register(registry).onError(throwable -> reference.set(new ResultBackedExecResult<>(Result.<T>error(throwable)))).onComplete(exec -> latch.countDown()).start(execution -> {
reference.set(ExecResult.complete());
Promise<T> promise = func.apply(execution);
if (promise == null) {
reference.set(null);
} else {
promise.then(t -> reference.set(new ResultBackedExecResult<>(Result.success(t))));
}
});
latch.await();
return reference.get();
}
Aggregations