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 isolate.load_balancer; | 6 library isolate.load_balancer; |
7 | 7 |
8 import 'dart:async' show Future; | 8 import 'dart:async' show Future; |
9 | 9 |
10 import 'runner.dart'; | 10 import 'runner.dart'; |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 int queueIndex = -1; | 260 int queueIndex = -1; |
261 | 261 |
262 // The service used to send commands to the other isolate. | 262 // The service used to send commands to the other isolate. |
263 Runner runner; | 263 Runner runner; |
264 | 264 |
265 _LoadBalancerEntry(Runner runner) : runner = runner; | 265 _LoadBalancerEntry(Runner runner) : runner = runner; |
266 | 266 |
267 /// Whether the entry is still in the queue. | 267 /// Whether the entry is still in the queue. |
268 bool get inQueue => queueIndex >= 0; | 268 bool get inQueue => queueIndex >= 0; |
269 | 269 |
270 Future run(LoadBalancer balancer, int load, function(argumen), argument, | 270 Future run(LoadBalancer balancer, int load, function(argument), argument, |
271 Duration timeout, onTimeout()) { | 271 Duration timeout, onTimeout()) { |
272 return runner.run(function, argument, | 272 return runner.run(function, argument, |
273 timeout: timeout, onTimeout: onTimeout).whenComplete(() { | 273 timeout: timeout, onTimeout: onTimeout).whenComplete(() { |
274 balancer._decreaseLoad(this, load); | 274 balancer._decreaseLoad(this, load); |
275 }); | 275 }); |
276 } | 276 } |
277 | 277 |
278 Future close() => runner.close(); | 278 Future close() => runner.close(); |
279 | 279 |
280 int compareTo(_LoadBalancerEntry other) => load - other.load; | 280 int compareTo(_LoadBalancerEntry other) => load - other.load; |
281 } | 281 } |
OLD | NEW |