| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 final Trace stackTrace; | 65 final Trace stackTrace; |
| 66 | 66 |
| 67 Task(fn(), String description, TaskQueue queue) | 67 Task(fn(), String description, TaskQueue queue) |
| 68 : this._(fn, description, queue, null, queue.contents.length); | 68 : this._(fn, description, queue, null, queue.contents.length); |
| 69 | 69 |
| 70 Task._child(fn(), String description, Task parent) | 70 Task._child(fn(), String description, Task parent) |
| 71 : this._(fn, description, parent.queue, parent, parent.children.length); | 71 : this._(fn, description, parent.queue, parent, parent.children.length); |
| 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 = new Trace.current() { |
| 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.value().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; |
| (...skipping 68 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 |