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

Side by Side Diff: pkg/barback/lib/src/node_streams.dart

Issue 261823008: Reorganize barback's source files. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: re-add barback/lib/src/internal_asset.dart Created 6 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library barback.node_streams;
6
7 import 'dart:async';
8
9 import 'asset_node.dart';
10 import 'log.dart';
11 import 'node_status.dart';
12 import 'stream_pool.dart';
13
14 /// A collection of streams that are common to nodes in barback's package graph.
15 class NodeStreams {
16 /// A stream that emits an event every time the node's status changes.
17 ///
18 /// This will emit the new status. It's guaranteed to emit an event only when
19 /// the status changes from the previous value. To ensure this, callers should
20 /// emit status changes using [changeStatus]. The initial status is assumed to
21 /// be [NodeStatus.RUNNING].
22 Stream<NodeStatus> get onStatusChange => _onStatusChangeController.stream;
23 final _onStatusChangeController =
24 new StreamController<NodeStatus>.broadcast(sync: true);
25
26 /// A stream that emits any new assets produced by the node.
27 ///
28 /// Assets are emitted synchronously to ensure that any changes are thoroughly
29 /// propagated as soon as they occur.
30 Stream<AssetNode> get onAsset => onAssetPool.stream;
31 final onAssetPool = new StreamPool<AssetNode>.broadcast();
32 final onAssetController =
33 new StreamController<AssetNode>.broadcast(sync: true);
34
35 /// A stream that emits an event whenever any the node logs an entry.
36 Stream<LogEntry> get onLog => onLogPool.stream;
37 final onLogPool = new StreamPool<LogEntry>.broadcast();
38 final onLogController = new StreamController<LogEntry>.broadcast(sync: true);
39
40 var _previousStatus = NodeStatus.RUNNING;
41
42 /// Whether [this] has been closed.
43 bool get isClosed => onAssetController.isClosed;
44
45 NodeStreams() {
46 onAssetPool.add(onAssetController.stream);
47 onLogPool.add(onLogController.stream);
48 }
49
50 /// Emits a status change notification via [onStatusChange].
51 ///
52 /// This guarantees that a change notification won't be emitted if the status
53 /// didn't actually change.
54 void changeStatus(NodeStatus status) {
55 if (_previousStatus != status) _onStatusChangeController.add(status);
56 }
57
58 /// Closes all the streams.
59 void close() {
60 _onStatusChangeController.close();
61 onAssetController.close();
62 onAssetPool.close();
63 onLogController.close();
64 onLogPool.close();
65 }
66 }
OLDNEW
« 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