@Test public void async() throws CheckedFutureException { ExecutorService es = Executors.newCachedThreadPool(); try { FuturePool pool = FuturePool.apply(es); Thread originalThread = Thread.currentThread(); Future<Integer> future = pool.async(() -> { assertNotEquals(originalThread, Thread.currentThread()); return 1; }); assertEquals(new Integer(1), get(future)); } finally { es.shutdown(); } }
public final <T> Future<T> async(final Supplier<T> s) { try { final AsyncPromise<T> p = new AsyncPromise<>(s); executor.submit(p); return p; } catch (final RejectedExecutionException ex) { return Future.exception(ex); } }
FuturePool { public final <T> Future<T> async(final Supplier<T> s) { try { final AsyncPromise<T> p = new AsyncPromise<>(s); executor.submit(p); return p; } catch (final RejectedExecutionException ex) { return Future.exception(ex); } } }
FuturePool { public final <T> Future<T> async(final Supplier<T> s) { try { final AsyncPromise<T> p = new AsyncPromise<>(s); executor.submit(p); return p; } catch (final RejectedExecutionException ex) { return Future.exception(ex); } } private  FuturePool(final ExecutorService executor); }
FuturePool { public final <T> Future<T> async(final Supplier<T> s) { try { final AsyncPromise<T> p = new AsyncPromise<>(s); executor.submit(p); return p; } catch (final RejectedExecutionException ex) { return Future.exception(ex); } } private  FuturePool(final ExecutorService executor); static FuturePool apply(final ExecutorService executor); final Future<T> isolate(final Supplier<Future<T>> s); final Future<T> async(final Supplier<T> s); }
FuturePool { public final <T> Future<T> async(final Supplier<T> s) { try { final AsyncPromise<T> p = new AsyncPromise<>(s); executor.submit(p); return p; } catch (final RejectedExecutionException ex) { return Future.exception(ex); } } private  FuturePool(final ExecutorService executor); static FuturePool apply(final ExecutorService executor); final Future<T> isolate(final Supplier<Future<T>> s); final Future<T> async(final Supplier<T> s);  }