Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Unified Diff: pkg/barback/lib/src/node_streams.dart

Issue 255483002: Expand barback's notion of dirtiness to understand declaredness. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/barback/lib/src/node_status.dart ('k') | pkg/barback/lib/src/package_graph.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/barback/lib/src/node_streams.dart
diff --git a/pkg/barback/lib/src/node_streams.dart b/pkg/barback/lib/src/node_streams.dart
index 7b6632fae28503580b68cbc311ec1e3d2ce1813a..194314f656c09a5b19a601f5e441663b3d77a43c 100644
--- a/pkg/barback/lib/src/node_streams.dart
+++ b/pkg/barback/lib/src/node_streams.dart
@@ -8,16 +8,20 @@ import 'dart:async';
import 'asset_node.dart';
import 'log.dart';
+import 'node_status.dart';
import 'stream_pool.dart';
/// A collection of streams that are common to nodes in barback's package graph.
class NodeStreams {
- /// A stream that emits an event whenever the node is no longer dirty.
+ /// A stream that emits an event every time the node's status changes.
///
- /// This is synchronous in order to guarantee that it will emit an event as
- /// soon as [isDirty] flips from `true` to `false`.
- Stream get onDone => onDoneController.stream;
- final onDoneController = new StreamController.broadcast(sync: true);
+ /// This will emit the new status. It's guaranteed to emit an event only when
+ /// the status changes from the previous value. To ensure this, callers should
+ /// emit status changes using [changeStatus]. The initial status is assumed to
+ /// be [NodeStatus.RUNNING].
+ Stream<NodeStatus> get onStatusChange => _onStatusChangeController.stream;
+ final _onStatusChangeController =
+ new StreamController<NodeStatus>.broadcast(sync: true);
/// A stream that emits any new assets produced by the node.
///
@@ -33,14 +37,24 @@ class NodeStreams {
final onLogPool = new StreamPool<LogEntry>.broadcast();
final onLogController = new StreamController<LogEntry>.broadcast(sync: true);
+ var _previousStatus = NodeStatus.RUNNING;
+
NodeStreams() {
onAssetPool.add(onAssetController.stream);
onLogPool.add(onLogController.stream);
}
+ /// Emits a status change notification via [onStatusChange].
+ ///
+ /// This guarantees that a change notification won't be emitted if the status
+ /// didn't actually change.
+ void changeStatus(NodeStatus status) {
+ if (_previousStatus != status) _onStatusChangeController.add(status);
+ }
+
/// Closes all the streams.
void close() {
- onDoneController.close();
+ _onStatusChangeController.close();
onAssetController.close();
onAssetPool.close();
onLogController.close();
« no previous file with comments | « pkg/barback/lib/src/node_status.dart ('k') | pkg/barback/lib/src/package_graph.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698