@Test public void testRunSuccessful() throws Exception { assertThat( Async.run(() -> "anything").get(), is("anything") ); }
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();  }