@Override public void onFailure(Throwable throwable) { promise.fail(throwable); } });
@Override public void onFailure(Throwable throwable) { promise.fail(throwable); } });
@Override public void onFailure(Throwable throwable) { promise.fail(throwable); } });
@Override public void onFailure(Throwable throwable) { result.fail(throwable); } });
@Override public void onFailure(Throwable throwable) throws Exception { result.fail(throwable); } });
@Override public void onSuccess(V value) throws Exception { try { successHandler.accept(value); } catch (Exception t) { fail(t); } }
@Override public void onSuccess(V value) throws Exception { try { promise.success(mapper.apply(value)); } catch (Exception e) { promise.fail(e); } }
@Override public void onSuccess(V value) throws Exception { try { mapper.apply(value).chain(result); } catch (Exception throwable) { result.fail(throwable); } }
@Override public void onSuccess(V value) throws Exception { try { successHandler.invoke(value); } catch (Exception e) { promise.fail(e); } }
@Override public void onSuccess(V value) throws Exception { try { successHandler.invoke(value); } catch (Exception t) { fail(t); } }
/** * Forks the given computation and returns a {@link Promise} for the computed value. * <p> * Forks the computation, which means that the current <tt>CallContext</tt> is transferred to the new thread, * and returns the result of the computation as promise. * <p> * If the executor for the given category is saturated (all threads are active and the queue is full) this * will drop the computation and the promise will be sent a <tt>RejectedExecutionException</tt>. * * @param category the category which implies which executor to use. * @param computation the computation which eventually yields the resulting value * @param <V> the type of the resulting value * @return a promise which will either be eventually supplied with the result of the computation or with an error */ public <V> Promise<V> fork(String category, final Supplier<V> computation) { final Promise<V> result = new Promise<>(); executor(category).dropOnOverload(() -> result.fail(new RejectedExecutionException())).fork(() -> { try { result.success(computation.get()); } catch (Exception t) { result.fail(t); } }); return result; }
/** * Updates the entity in the database asynchronous using a dedicated thread pool. * * @param entity the entity to be written into the DB * @param <E> the type of the entity to update * @return a {@link Promise} handling the update process */ public <E extends Entity> Promise<E> updateAsync(E entity) { Promise<E> promise = new Promise<>(); tasks.executor(ASYNC_UPDATER).start(() -> { try { update(entity); promise.success(entity); } catch (Exception e) { promise.fail(e); } }); return promise; }