| 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 task; | 5 library task; |
| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 : queue = queue, | 73 : queue = queue, |
| 74 stackTrace = new Trace.current() { | 74 stackTrace = new Trace.current() { |
| 75 this.fn = () { | 75 this.fn = () { |
| 76 if (state != TaskState.WAITING) { | 76 if (state != TaskState.WAITING) { |
| 77 throw new StateError("Can't run $state task '$this'."); | 77 throw new StateError("Can't run $state task '$this'."); |
| 78 } | 78 } |
| 79 | 79 |
| 80 _state = TaskState.RUNNING; | 80 _state = TaskState.RUNNING; |
| 81 var future = new Future.value().then((_) => fn()) | 81 var future = new Future.value().then((_) => fn()) |
| 82 .whenComplete(() { | 82 .whenComplete(() { |
| 83 if (_childGroup == null || _childGroup.completed) return; | 83 if (_childGroup == null || _childGroup.completed) return null; |
| 84 return _childGroup.future; | 84 return _childGroup.future; |
| 85 }); | 85 }); |
| 86 chainToCompleter(future, _resultCompleter); | 86 chainToCompleter(future, _resultCompleter); |
| 87 return future; | 87 return future; |
| 88 }; | 88 }; |
| 89 | 89 |
| 90 // If the parent queue experiences an error before this task has started | 90 // If the parent queue experiences an error before this task has started |
| 91 // running, pipe that error out through [result]. This ensures that we don't | 91 // running, pipe that error out through [result]. This ensures that we don't |
| 92 // get deadlocked by something like `expect(schedule(...), completes)`. | 92 // get deadlocked by something like `expect(schedule(...), completes)`. |
| 93 queue.onTasksComplete.catchError((e) { | 93 queue.onTasksComplete.catchError((e) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 final String name; | 153 final String name; |
| 154 | 154 |
| 155 /// Whether the state indicates that the task has finished running. This is | 155 /// Whether the state indicates that the task has finished running. This is |
| 156 /// true for both the [SUCCESS] and [ERROR] states. | 156 /// true for both the [SUCCESS] and [ERROR] states. |
| 157 bool get isDone => this == SUCCESS || this == ERROR; | 157 bool get isDone => this == SUCCESS || this == ERROR; |
| 158 | 158 |
| 159 const TaskState._(this.name); | 159 const TaskState._(this.name); |
| 160 | 160 |
| 161 String toString() => name; | 161 String toString() => name; |
| 162 } | 162 } |
| OLD | NEW |