### Question:
AsyncListenableFuture extends FiberAsync<V, ExecutionException> { public static <V> V get(ListenableFuture<V> future) throws ExecutionException, InterruptedException, SuspendExecution { if (Fiber.isCurrentFiber() && !future.isDone()) return new AsyncListenableFuture<>(future).run(); else return future.get(); } private  AsyncListenableFuture(ListenableFuture<V> future); static V get(ListenableFuture<V> future); static V get(ListenableFuture<V> future, long timeout, TimeUnit unit); static V get(ListenableFuture<V> future, Timeout timeout);  }### Answer:
@Test public void simpleTest1() throws Exception { final SettableFuture<String> fut = SettableFuture.create(); final Fiber<String> fiber = new Fiber<>(scheduler, new SuspendableCallable<String>() { @Override public String run() throws SuspendExecution, InterruptedException { try { return AsyncListenableFuture.get(fut); } catch (ExecutionException e) { throw new RuntimeException(e); } } }).start(); new Thread(new Runnable() { @Override public void run() { try { Thread.sleep(200); fut.set("hi!"); } catch (InterruptedException e) { } } }).start(); assertThat(fiber.get(), equalTo("hi!")); }
@Test public void testException() throws Exception { final SettableFuture<String> fut = SettableFuture.create(); final Fiber<String> fiber = new Fiber<>(scheduler, new SuspendableCallable<String>() { @Override public String run() throws SuspendExecution, InterruptedException { try { String res = AsyncListenableFuture.get(fut); fail(); return res; } catch (ExecutionException e) { throw Exceptions.rethrow(e.getCause()); } } }).start(); new Thread(new Runnable() { @Override public void run() { try { Thread.sleep(200); fut.setException(new RuntimeException("haha!")); } catch (InterruptedException e) { } } }).start(); try { fiber.get(); fail(); } catch (ExecutionException e) { assertThat(e.getCause().getMessage(), equalTo("haha!")); } }
@Test public void testException2() throws Exception { final ListenableFuture<String> fut = new AbstractFuture<String>() { { setException(new RuntimeException("haha!")); } }; final Fiber<String> fiber = new Fiber<>(new SuspendableCallable<String>() { @Override public String run() throws SuspendExecution, InterruptedException { try { String res = AsyncListenableFuture.get(fut); fail(); return res; } catch (ExecutionException e) { throw Exceptions.rethrow(e.getCause()); } } }).start(); try { fiber.get(); fail(); } catch (ExecutionException e) { assertThat(e.getCause().getMessage(), equalTo("haha!")); } }