Future divide(String name, int count, { dynamic next(), dynamic collect(List inputs) })

Source

Future<dynamic> divide(String name, int count,
    {dynamic next(), dynamic collect(List<dynamic> inputs)}) async {
  if (next == null) {
    var i = 0;
    next = () {
      return i++;
    };
  }

  var futures = <Future>[];
  for (var i = 1; i <= count; i++) {
    var input = next();
    futures.add(getAvailableWorker().callMethod(name, input));
  }

  var outs = await Future.wait(futures);

  return collect != null ? await collect(outs) : outs;
}