| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library schedule; | 5 library schedule; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import 'package:stack_trace/stack_trace.dart'; | 10 import 'package:stack_trace/stack_trace.dart'; |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 return task.result; | 432 return task.result; |
| 433 } | 433 } |
| 434 | 434 |
| 435 /// Runs all the tasks in this queue in order. | 435 /// Runs all the tasks in this queue in order. |
| 436 Future _run() { | 436 Future _run() { |
| 437 _schedule._currentQueue = this; | 437 _schedule._currentQueue = this; |
| 438 _schedule.heartbeat(); | 438 _schedule.heartbeat(); |
| 439 return Future.forEach(_contents, (task) { | 439 return Future.forEach(_contents, (task) { |
| 440 _schedule._currentTask = task; | 440 _schedule._currentTask = task; |
| 441 if (_error != null) throw _error; | 441 if (_error != null) throw _error; |
| 442 if (_aborted) return; | 442 if (_aborted) return null; |
| 443 | 443 |
| 444 _taskFuture = new SubstituteFuture(task.fn()); | 444 _taskFuture = new SubstituteFuture(task.fn()); |
| 445 return _taskFuture.whenComplete(() { | 445 return _taskFuture.whenComplete(() { |
| 446 _taskFuture = null; | 446 _taskFuture = null; |
| 447 _schedule.heartbeat(); | 447 _schedule.heartbeat(); |
| 448 }).catchError((e, trace) { | 448 }).catchError((e, trace) { |
| 449 var error = new ScheduleError.from(_schedule, e, stackTrace: trace); | 449 var error = new ScheduleError.from(_schedule, e, stackTrace: trace); |
| 450 _signalError(error); | 450 _signalError(error); |
| 451 throw _error; | 451 throw _error; |
| 452 }); | 452 }); |
| 453 }).whenComplete(() { | 453 }).whenComplete(() { |
| 454 _schedule._currentTask = null; | 454 _schedule._currentTask = null; |
| 455 }).then((_) { | 455 }).then((_) { |
| 456 _onTasksCompleteCompleter.complete(); | 456 _onTasksCompleteCompleter.complete(); |
| 457 }).catchError((e, stackTrace) { | 457 }).catchError((e, stackTrace) { |
| 458 _onTasksCompleteCompleter.completeError(e, stackTrace); | 458 _onTasksCompleteCompleter.completeError(e, stackTrace); |
| 459 throw e; | 459 throw e; |
| 460 }).whenComplete(() { | 460 }).whenComplete(() { |
| 461 if (pendingCallbacks.isEmpty) return; | 461 if (pendingCallbacks.isEmpty) return null; |
| 462 return _noPendingCallbacks.catchError((e, stackTrace) { | 462 return _noPendingCallbacks.catchError((e, stackTrace) { |
| 463 // Signal the error rather than passing it through directly so that if a | 463 // Signal the error rather than passing it through directly so that if a |
| 464 // timeout happens after an in-task error, both are reported. | 464 // timeout happens after an in-task error, both are reported. |
| 465 _signalError(new ScheduleError.from(_schedule, e, | 465 _signalError(new ScheduleError.from(_schedule, e, |
| 466 stackTrace: stackTrace)); | 466 stackTrace: stackTrace)); |
| 467 }); | 467 }); |
| 468 }).whenComplete(() { | 468 }).whenComplete(() { |
| 469 _schedule.heartbeat(); | 469 _schedule.heartbeat(); |
| 470 // If the tasks were otherwise successful, make sure we throw any | 470 // If the tasks were otherwise successful, make sure we throw any |
| 471 // out-of-band errors. If a task failed, make sure we throw the most | 471 // out-of-band errors. If a task failed, make sure we throw the most |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 return fn(arg); | 511 return fn(arg); |
| 512 } catch (e, stackTrace) { | 512 } catch (e, stackTrace) { |
| 513 var error = new ScheduleError.from( | 513 var error = new ScheduleError.from( |
| 514 _schedule, e, stackTrace: stackTrace); | 514 _schedule, e, stackTrace: stackTrace); |
| 515 if (_timedOut()) { | 515 if (_timedOut()) { |
| 516 _schedule._signalPostTimeoutError(error); | 516 _schedule._signalPostTimeoutError(error); |
| 517 } else { | 517 } else { |
| 518 _schedule.signalError(error); | 518 _schedule.signalError(error); |
| 519 } | 519 } |
| 520 } finally { | 520 } finally { |
| 521 if (_timedOut()) return; | 521 if (_timedOut()) return null; |
| 522 | 522 |
| 523 _pendingCallbacks.remove(pendingCallback); | 523 _pendingCallbacks.remove(pendingCallback); |
| 524 if (_pendingCallbacks.isEmpty && !isRunningTasks) { | 524 if (_pendingCallbacks.isEmpty && !isRunningTasks) { |
| 525 _noPendingCallbacksCompleter.complete(); | 525 _noPendingCallbacksCompleter.complete(); |
| 526 } | 526 } |
| 527 } | 527 } |
| 528 }; | 528 }; |
| 529 } | 529 } |
| 530 | 530 |
| 531 /// Signals that an out-of-band error has been detected and the queue should | 531 /// Signals that an out-of-band error has been detected and the queue should |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 /// The string description of the callback. | 606 /// The string description of the callback. |
| 607 String get description { | 607 String get description { |
| 608 if (_description == null) _description = _thunk(); | 608 if (_description == null) _description = _thunk(); |
| 609 return _description; | 609 return _description; |
| 610 } | 610 } |
| 611 | 611 |
| 612 String toString() => description; | 612 String toString() => description; |
| 613 | 613 |
| 614 PendingCallback._(this._thunk); | 614 PendingCallback._(this._thunk); |
| 615 } | 615 } |
| OLD | NEW |