create static method

Future<LoadBalancer> create(
  1. int size,
  2. Future<Runner> createRunner()
)

Asynchronously create size runners and create a LoadBalancer of those.

This is a helper function that makes it easy to create a LoadBalancer with asynchronously created runners, for example:

var isolatePool = LoadBalancer.create(10, IsolateRunner.spawn);

Implementation

static Future<LoadBalancer> create(
    int size, Future<Runner> Function() createRunner) {
  return Future.wait(Iterable.generate(size, (_) => createRunner()),
      cleanUp: (Runner runner) {
    runner.close();
  }).then((runners) => LoadBalancer(runners));
}