Пример #1
0
  public void set(T result) {

    try {

      final Object use = result;

      if (pipeline == null || pipeline.functions.length == 0) {
        this.result.lazySet(use);
        done();
        return;
      }
      Function op = pipeline.functions[0];
      if (this.pipeline.executors[0] != null) {

        this.pipeline.executors[0].execute(
            () -> {
              set(() -> (T) op.apply(use), 1);
            });

      } else {

        set(() -> (T) op.apply(use), 1);
      }
    } catch (Throwable t) {

      completeExceptionally(t);
    }
  }
Пример #2
0
  private void set(Supplier<T> result, int index) {
    try {

      Object current = result.get();

      final Object use = current;
      if (index < pipeline.functions.length) {
        Function op = pipeline.functions[index];
        this.pipeline.executors[index].execute(
            () -> {
              set(() -> (T) op.apply(use), index + 1);
            });
        return;
      }

      this.result.lazySet(current);
      done();

    } catch (Throwable t) {
      if (t instanceof CompletedException) {
        if (this.doFinally != null) doFinally.accept(this);
      }

      completeExceptionally(t);
    }
  }
Пример #3
0
 /**
  * Internal conversion method to convert CompletableFutures to FastFuture.
  *
  * @param cf
  * @return
  */
 public static <T> FastFuture<T> fromCompletableFuture(CompletableFuture<T> cf) {
   FastFuture<T> f = new FastFuture<>();
   cf.thenAccept(i -> f.set(i));
   cf.exceptionally(
       t -> {
         f.completedExceptionally(t);
         return f.join();
       });
   return f;
 }