@Test public void testNoRecursiveToString() { final AtomicReference<Runnable> callbackRef = new AtomicReference<>(); ListenableFuture<String> future = CallbackToFutureAdapter.getFuture( new CallbackToFutureAdapter.Resolver<String>() { @Override public Object attachCompleter(final Completer<String> completer) { Runnable callback = new Runnable() { @Override public void run() { completer.set("my special result"); } @Override public String toString() { return "custom callback, completer=[" + completer + "]"; } }; callbackRef.set(callback); return callback; } }); assertThat(future.isDone()).isFalse(); assertThat(future.toString()).contains("custom callback"); callbackRef.get().run(); 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);  }