@Test public void testSuccess() { final AtomicReference<Completer<String>> completerRef = new AtomicReference<>(); ListenableFuture<String> future = CallbackToFutureAdapter.getFuture( new CallbackToFutureAdapter.Resolver<String>() { @Override public Object attachCompleter(Completer<String> completer) { completerRef.set(completer); return "my special callback"; } }); assertThat(future.isDone()).isFalse(); assertThat(future.toString()).contains("my special callback"); completerRef.get().set("my special result"); assertFutureCompletedWith(future, "my special result"); }
@NonNull public static <T> ListenableFuture<T> getFuture(@NonNull Resolver<T> callback) { Completer<T> completer = new Completer<>(); SafeFuture<T> safeFuture = new SafeFuture<>(completer); completer.future = safeFuture; completer.tag = callback.getClass(); final Object tag; try { tag = callback.attachCompleter(completer); if (tag != null) { completer.tag = tag; } } catch (Exception e) { safeFuture.setException(e); } return safeFuture; }
CallbackToFutureAdapter { @NonNull public static <T> ListenableFuture<T> getFuture(@NonNull Resolver<T> callback) { Completer<T> completer = new Completer<>(); SafeFuture<T> safeFuture = new SafeFuture<>(completer); completer.future = safeFuture; completer.tag = callback.getClass(); final Object tag; try { tag = callback.attachCompleter(completer); if (tag != null) { completer.tag = tag; } } catch (Exception e) { safeFuture.setException(e); } return safeFuture; } }
CallbackToFutureAdapter { @NonNull public static <T> ListenableFuture<T> getFuture(@NonNull Resolver<T> callback) { Completer<T> completer = new Completer<>(); SafeFuture<T> safeFuture = new SafeFuture<>(completer); completer.future = safeFuture; completer.tag = callback.getClass(); final Object tag; try { tag = callback.attachCompleter(completer); if (tag != null) { completer.tag = tag; } } catch (Exception e) { safeFuture.setException(e); } return safeFuture; } private  CallbackToFutureAdapter(); }
CallbackToFutureAdapter { @NonNull public static <T> ListenableFuture<T> getFuture(@NonNull Resolver<T> callback) { Completer<T> completer = new Completer<>(); SafeFuture<T> safeFuture = new SafeFuture<>(completer); completer.future = safeFuture; completer.tag = callback.getClass(); final Object tag; try { tag = callback.attachCompleter(completer); if (tag != null) { completer.tag = tag; } } catch (Exception e) { safeFuture.setException(e); } return safeFuture; } private  CallbackToFutureAdapter(); @NonNull static ListenableFuture<T> getFuture(@NonNull Resolver<T> callback); }
CallbackToFutureAdapter { @NonNull public static <T> ListenableFuture<T> getFuture(@NonNull Resolver<T> callback) { Completer<T> completer = new Completer<>(); SafeFuture<T> safeFuture = new SafeFuture<>(completer); completer.future = safeFuture; completer.tag = callback.getClass(); final Object tag; try { tag = callback.attachCompleter(completer); if (tag != null) { completer.tag = tag; } } catch (Exception e) { safeFuture.setException(e); } return safeFuture; } private  CallbackToFutureAdapter(); @NonNull static ListenableFuture<T> getFuture(@NonNull Resolver<T> callback);  }