Index: lib/loadbalancer.dart |
diff --git a/lib/loadbalancer.dart b/lib/loadbalancer.dart |
index fdb5d0bcf70bd75b011ebc8d27eeda21b3682e5f..a3fb9b1b03004aae1cbc2141f3eef5ffdfa0581d 100644 |
--- a/lib/loadbalancer.dart |
+++ b/lib/loadbalancer.dart |
@@ -56,9 +56,11 @@ class LoadBalancer implements Runner { |
* var isolatePool = LoadBalancer.create(10, IsolateRunner.spawn); |
*/ |
static Future<LoadBalancer> create(int size, Future<Runner> createRunner()) { |
- return Future.wait(new Iterable.generate(size, (_) => createRunner()), |
- cleanUp: (Runner runner) { runner.close(); }) |
- .then((runners) => new LoadBalancer(runners)); |
+ return Future |
+ .wait(new Iterable.generate(size, (_) => createRunner()), |
+ cleanUp: (Runner runner) { |
Lasse Reichstein Nielsen
2015/02/26 10:59:14
indent cleanUp to after the '('. Putting the body
|
+ runner.close(); |
+ }).then((runners) => new LoadBalancer(runners)); |
} |
static List<_LoadBalancerEntry> _createEntries(Iterable<Runner> runners) { |
@@ -79,9 +81,8 @@ class LoadBalancer implements Runner { |
* the runner running the function, which will handle a timeout |
* as normal. |
*/ |
- Future run(function(argument), argument, {Duration timeout, |
- onTimeout(), |
- int load: 100}) { |
+ Future run(function(argument), argument, |
+ {Duration timeout, onTimeout(), int load: 100}) { |
Lasse Reichstein Nielsen
2015/02/26 10:59:14
Indent "{" to after then "(". That is:
Future run(
|
RangeError.checkNotNegative(load, "load"); |
_LoadBalancerEntry entry = _first; |
_increaseLoad(entry, load); |
@@ -105,14 +106,12 @@ class LoadBalancer implements Runner { |
* as normal. |
*/ |
List<Future> runMultiple(int count, function(argument), argument, |
- {Duration timeout, |
- onTimeout(), |
- int load: 100}) { |
+ {Duration timeout, onTimeout(), int load: 100}) { |
Lasse Reichstein Nielsen
2015/02/26 10:59:14
Indent '{ ' to after '('.
|
RangeError.checkValueInInterval(count, 1, _length, "count"); |
RangeError.checkNotNegative(load, "load"); |
if (count == 1) { |
- return list1(run(function, argument, load: load, |
- timeout: timeout, onTimeout: onTimeout)); |
+ return list1(run(function, argument, |
+ load: load, timeout: timeout, onTimeout: onTimeout)); |
Lasse Reichstein Nielsen
2015/02/26 10:59:14
Indent arguments to after '(' or put all arguments
|
} |
List result = new List<Future>(count); |
if (count == _length) { |
@@ -120,8 +119,8 @@ class LoadBalancer implements Runner { |
for (int i = 0; i < count; i++) { |
_LoadBalancerEntry entry = _queue[i]; |
entry.load += load; |
- result[i] = entry.run(this, load, function, argument, |
- timeout, onTimeout); |
+ result[i] = |
+ entry.run(this, load, function, argument, timeout, onTimeout); |
} |
} else { |
// Remove the [count] least loaded services and run the |
@@ -136,8 +135,8 @@ class LoadBalancer implements Runner { |
_LoadBalancerEntry entry = entries[i]; |
entry.load += load; |
_add(entry); |
- result[i] = entry.run(this, load, function, argument, |
- timeout, onTimeout); |
+ result[i] = |
+ entry.run(this, load, function, argument, timeout, onTimeout); |
} |
} |
return result; |
@@ -145,8 +144,8 @@ class LoadBalancer implements Runner { |
Future close() { |
if (_stopFuture != null) return _stopFuture; |
- _stopFuture = MultiError.waitUnordered(_queue.take(_length) |
- .map((e) => e.close())); |
+ _stopFuture = |
+ MultiError.waitUnordered(_queue.take(_length).map((e) => e.close())); |
// Remove all entries. |
for (int i = 0; i < _length; i++) _queue[i].queueIndex = -1; |
_queue = null; |
@@ -183,7 +182,7 @@ class LoadBalancer implements Runner { |
*/ |
void _bubbleDown(_LoadBalancerEntry element, int index) { |
while (true) { |
- int childIndex = index * 2 + 1; // Left child index. |
+ int childIndex = index * 2 + 1; // Left child index. |
Lasse Reichstein Nielsen
2015/02/26 10:59:14
There should always be two spaces before an end-of
|
if (childIndex >= _length) break; |
_LoadBalancerEntry child = _queue[childIndex]; |
int rightChildIndex = childIndex + 1; |
@@ -283,16 +282,16 @@ class _LoadBalancerEntry implements Comparable<_LoadBalancerEntry> { |
// The service used to send commands to the other isolate. |
Runner runner; |
- _LoadBalancerEntry(Runner runner) |
- : runner = runner; |
+ _LoadBalancerEntry(Runner runner) : runner = runner; |
/** Whether the entry is still in the queue. */ |
bool get inQueue => queueIndex >= 0; |
Future run(LoadBalancer balancer, int load, function(argumen), argument, |
- Duration timeout, onTimeout()) { |
- return runner.run(function, argument, |
- timeout: timeout, onTimeout: onTimeout).whenComplete(() { |
+ Duration timeout, onTimeout()) { |
+ return runner |
+ .run(function, argument, timeout: timeout, onTimeout: onTimeout) |
+ .whenComplete(() { |
balancer._decreaseLoad(this, load); |
Lasse Reichstein Nielsen
2015/02/26 10:59:14
Indent body by four more.
|
}); |
} |
@@ -301,5 +300,3 @@ class _LoadBalancerEntry implements Comparable<_LoadBalancerEntry> { |
int compareTo(_LoadBalancerEntry other) => load - other.load; |
} |
- |
- |