@Override protected Promise<R> run(final Context context) throws Exception { Executor executor = (Executor) context.getEngineProperty(CALLABLE_SERVICE_EXECUTOR); if (executor == null) { throw new IllegalStateException( "To use AsyncCallableTask you must first register an executor with the engine using AsyncCallableTask.register"); } final SettablePromise<R> promise = Promises.settable(); executor.execute(() -> { try { promise.done(_syncJob.call()); } catch (Throwable t) { promise.fail(t); } } ); return promise; } }
@Override protected Promise<R> run(final Context context) throws Exception { Executor executor = (Executor) context.getEngineProperty(CALLABLE_SERVICE_EXECUTOR); if (executor == null) { throw new IllegalStateException( "To use AsyncCallableTask you must first register an executor with the engine using AsyncCallableTask.register"); } final SettablePromise<R> promise = Promises.settable(); executor.execute(() -> { try { promise.done(_syncJob.call()); } catch (Throwable t) { promise.fail(t); } } ); return promise; } }