use of ratpack.registry.RegistrySpec in project ratpack by ratpack.
the class DefaultExecHarness method run.
@Override
public void run(Action<? super RegistrySpec> registry, Action<? super Execution> action) throws Exception {
final AtomicReference<Throwable> thrown = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
controller.fork().onError(thrown::set).register(registry).onComplete(e -> latch.countDown()).start(action::execute);
latch.await();
Throwable throwable = thrown.get();
if (throwable != null) {
throw Exceptions.toException(throwable);
}
}
use of ratpack.registry.RegistrySpec 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