All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.edgar615.util.vertx.task.ParTaskImpl Maven / Gradle / Ivy

There is a newer version: 1.0.14
Show newest version
package com.github.edgar615.util.vertx.task;

import io.vertx.core.CompositeFuture;
import io.vertx.core.Future;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Edgar on 2016/7/21.
 *
 * @author Edgar  Date 2016/7/21
 */
class ParTaskImpl extends BaseTask> {

  ParTaskImpl(String name, List> futures) {
    super(name, Future.>future());
    final int size = futures.size();
    List copyFuture = new ArrayList<>(size);
    for (int i = 0; i < size; i++) {
      copyFuture.add(futures.get(i));
    }
    CompositeFuture compositeFuture = CompositeFuture.all(copyFuture);
    compositeFuture.setHandler(ar -> {
      if (ar.succeeded()) {
        List results = new ArrayList<>(size);
        for (int i = 0; i < size; i++) {
          results.add((T) ar.result().resultAt(i));
        }
        complete(results);
      } else {
        fail(ar.cause());
      }
    });
  }

  ParTaskImpl(List> futures) {
    this("ParTask", futures);
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy