OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 barback.transformer.base_transform; | 5 library barback.transformer.base_transform; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import '../asset/asset_id.dart'; | 9 import '../asset/asset_id.dart'; |
10 import '../graph/transform_node.dart'; | 10 import '../graph/transform_node.dart'; |
(...skipping 29 matching lines...) Expand all Loading... |
40 | 40 |
41 /// A logger so that the [Transformer] can report build details. | 41 /// A logger so that the [Transformer] can report build details. |
42 TransformLogger get logger => _logger; | 42 TransformLogger get logger => _logger; |
43 TransformLogger _logger; | 43 TransformLogger _logger; |
44 | 44 |
45 BaseTransform(this._node) { | 45 BaseTransform(this._node) { |
46 _logger = new TransformLogger((asset, level, message, span) { | 46 _logger = new TransformLogger((asset, level, message, span) { |
47 if (level == LogLevel.ERROR) _loggedError = true; | 47 if (level == LogLevel.ERROR) _loggedError = true; |
48 | 48 |
49 // If the log isn't already associated with an asset, use the primary. | 49 // If the log isn't already associated with an asset, use the primary. |
50 if (asset == null) asset = _node.primary.id; | 50 if (asset == null) asset = _node.info.primaryId; |
51 var entry = new LogEntry(_node.info, asset, level, message, span); | 51 var entry = new LogEntry(_node.info, asset, level, message, span); |
52 _onLogController.add(entry); | 52 _onLogController.add(entry); |
53 }); | 53 }); |
54 } | 54 } |
55 | 55 |
56 /// Consume a primary input so that it doesn't get processed by future | 56 /// Consume a primary input so that it doesn't get processed by future |
57 /// phases or emitted once processing has finished. | 57 /// phases or emitted once processing has finished. |
58 /// | 58 /// |
59 /// Normally each primary input will automatically be forwarded unless the | 59 /// Normally each primary input will automatically be forwarded unless the |
60 /// transformer overwrites it by emitting an input with the same id. This | 60 /// transformer overwrites it by emitting an input with the same id. This |
(...skipping 16 matching lines...) Expand all Loading... |
77 | 77 |
78 /// The ids of primary inputs that should be consumed. | 78 /// The ids of primary inputs that should be consumed. |
79 Set<AssetId> get consumedPrimaries => transform._consumedPrimaries; | 79 Set<AssetId> get consumedPrimaries => transform._consumedPrimaries; |
80 | 80 |
81 /// Whether the transform logged an error. | 81 /// Whether the transform logged an error. |
82 bool get loggedError => transform._loggedError; | 82 bool get loggedError => transform._loggedError; |
83 | 83 |
84 /// The stream of log entries emitted by the transformer during a run. | 84 /// The stream of log entries emitted by the transformer during a run. |
85 Stream<LogEntry> get onLog => transform._onLogController.stream; | 85 Stream<LogEntry> get onLog => transform._onLogController.stream; |
86 | 86 |
| 87 /// Whether the transform's input or id stream has been closed. |
| 88 /// |
| 89 /// See also [done]. |
| 90 bool get isDone; |
| 91 |
87 BaseTransformController(this.transform); | 92 BaseTransformController(this.transform); |
88 | 93 |
89 /// Notifies the [BaseTransform] that the transformation has finished being | 94 /// Mark this transform as finished emitting new inputs or input ids. |
90 /// applied. | 95 /// |
| 96 /// This is distinct from [cancel] in that it *doesn't* indicate that the |
| 97 /// transform is finished being used entirely. The transformer may still log |
| 98 /// messages and load secondary inputs. This just indicates that all the |
| 99 /// primary inputs are accounted for. |
| 100 void done(); |
| 101 |
| 102 /// Mark this transform as canceled. |
91 /// | 103 /// |
92 /// This will close any streams and release any resources that were allocated | 104 /// This will close any streams and release any resources that were allocated |
93 /// for the duration of the transformation. | 105 /// for the duration of the transformation. Unlike [done], this indicates that |
94 void close() { | 106 /// the transformation is no longer relevant; either it has returned, or |
| 107 /// something external has preemptively invalidated its results. |
| 108 void cancel() { |
| 109 done(); |
95 transform._onLogController.close(); | 110 transform._onLogController.close(); |
96 } | 111 } |
97 } | 112 } |
OLD | NEW |