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