@Test(expected = ExecutionException.class) public void testRunWithException() throws Exception { Async.run(() -> { throw new RuntimeException("Exception"); }).get(); }
public static <T> CompletableFuture<T> run(Callable<T> callable, ExecutorService executor) { ExecutorService executorService = ofNullable(executor).orElse(DEFAULT_EXECUTOR); CompletableFuture<T> result = new CompletableFuture<>(); CompletableFuture.runAsync(() -> { try { result.complete(callable.call()); } catch (Throwable e) { result.completeExceptionally(e); } }, executorService); return result; }
Async { public static <T> CompletableFuture<T> run(Callable<T> callable, ExecutorService executor) { ExecutorService executorService = ofNullable(executor).orElse(DEFAULT_EXECUTOR); CompletableFuture<T> result = new CompletableFuture<>(); CompletableFuture.runAsync(() -> { try { result.complete(callable.call()); } catch (Throwable e) { result.completeExceptionally(e); } }, executorService); return result; } }
Async { public static <T> CompletableFuture<T> run(Callable<T> callable, ExecutorService executor) { ExecutorService executorService = ofNullable(executor).orElse(DEFAULT_EXECUTOR); CompletableFuture<T> result = new CompletableFuture<>(); CompletableFuture.runAsync(() -> { try { result.complete(callable.call()); } catch (Throwable e) { result.completeExceptionally(e); } }, executorService); return result; }  }
Async { public static <T> CompletableFuture<T> run(Callable<T> callable, ExecutorService executor) { ExecutorService executorService = ofNullable(executor).orElse(DEFAULT_EXECUTOR); CompletableFuture<T> result = new CompletableFuture<>(); CompletableFuture.runAsync(() -> { try { result.complete(callable.call()); } catch (Throwable e) { result.completeExceptionally(e); } }, executorService); return result; }  static CompletableFuture<T> run(Callable<T> callable, ExecutorService executor); static CompletableFuture<T> run(Callable<T> callable); static ExecutorService getDefaultExecutor(); static ScheduledExecutorService defaultExecutorService(); }
Async { public static <T> CompletableFuture<T> run(Callable<T> callable, ExecutorService executor) { ExecutorService executorService = ofNullable(executor).orElse(DEFAULT_EXECUTOR); CompletableFuture<T> result = new CompletableFuture<>(); CompletableFuture.runAsync(() -> { try { result.complete(callable.call()); } catch (Throwable e) { result.completeExceptionally(e); } }, executorService); return result; }  static CompletableFuture<T> run(Callable<T> callable, ExecutorService executor); static CompletableFuture<T> run(Callable<T> callable); static ExecutorService getDefaultExecutor(); static ScheduledExecutorService defaultExecutorService();  }