| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /// A load-balancing runner pool. | 5 /// A load-balancing runner pool. |
| 6 library dart.pkg.isolate.loadbalancer; | 6 library isolate.load_balancer; |
| 7 | 7 |
| 8 import "runner.dart"; | 8 import 'dart:async' show Future; |
| 9 import "src/errors.dart"; | 9 |
| 10 import "src/lists.dart"; | 10 import 'runner.dart'; |
| 11 import "dart:async" show Future; | 11 import 'src/errors.dart'; |
| 12 import 'src/lists.dart'; |
| 12 | 13 |
| 13 /// A pool of runners, ordered by load. | 14 /// A pool of runners, ordered by load. |
| 14 /// | 15 /// |
| 15 /// Keeps a pool of runners, | 16 /// Keeps a pool of runners, |
| 16 /// and allows running function through the runner with the lowest current load. | 17 /// and allows running function through the runner with the lowest current load. |
| 17 class LoadBalancer implements Runner { | 18 class LoadBalancer implements Runner { |
| 18 // A heap-based priority queue of entries, prioritized by `load`. | 19 // A heap-based priority queue of entries, prioritized by `load`. |
| 19 // Each entry has its own entry in the queue, for faster update. | 20 // Each entry has its own entry in the queue, for faster update. |
| 20 List<_LoadBalancerEntry> _queue; | 21 List<_LoadBalancerEntry> _queue; |
| 21 | 22 |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 return runner.run(function, argument, | 272 return runner.run(function, argument, |
| 272 timeout: timeout, onTimeout: onTimeout).whenComplete(() { | 273 timeout: timeout, onTimeout: onTimeout).whenComplete(() { |
| 273 balancer._decreaseLoad(this, load); | 274 balancer._decreaseLoad(this, load); |
| 274 }); | 275 }); |
| 275 } | 276 } |
| 276 | 277 |
| 277 Future close() => runner.close(); | 278 Future close() => runner.close(); |
| 278 | 279 |
| 279 int compareTo(_LoadBalancerEntry other) => load - other.load; | 280 int compareTo(_LoadBalancerEntry other) => load - other.load; |
| 280 } | 281 } |
| OLD | NEW |