| 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.node_streams; | 5 library barback.node_streams; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'asset_node.dart'; | 9 import 'asset_node.dart'; |
| 10 import 'log.dart'; | 10 import 'log.dart'; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 final onAssetController = | 32 final onAssetController = |
| 33 new StreamController<AssetNode>.broadcast(sync: true); | 33 new StreamController<AssetNode>.broadcast(sync: true); |
| 34 | 34 |
| 35 /// A stream that emits an event whenever any the node logs an entry. | 35 /// A stream that emits an event whenever any the node logs an entry. |
| 36 Stream<LogEntry> get onLog => onLogPool.stream; | 36 Stream<LogEntry> get onLog => onLogPool.stream; |
| 37 final onLogPool = new StreamPool<LogEntry>.broadcast(); | 37 final onLogPool = new StreamPool<LogEntry>.broadcast(); |
| 38 final onLogController = new StreamController<LogEntry>.broadcast(sync: true); | 38 final onLogController = new StreamController<LogEntry>.broadcast(sync: true); |
| 39 | 39 |
| 40 var _previousStatus = NodeStatus.RUNNING; | 40 var _previousStatus = NodeStatus.RUNNING; |
| 41 | 41 |
| 42 /// Whether [this] has been closed. |
| 43 bool get isClosed => onAssetController.isClosed; |
| 44 |
| 42 NodeStreams() { | 45 NodeStreams() { |
| 43 onAssetPool.add(onAssetController.stream); | 46 onAssetPool.add(onAssetController.stream); |
| 44 onLogPool.add(onLogController.stream); | 47 onLogPool.add(onLogController.stream); |
| 45 } | 48 } |
| 46 | 49 |
| 47 /// Emits a status change notification via [onStatusChange]. | 50 /// Emits a status change notification via [onStatusChange]. |
| 48 /// | 51 /// |
| 49 /// This guarantees that a change notification won't be emitted if the status | 52 /// This guarantees that a change notification won't be emitted if the status |
| 50 /// didn't actually change. | 53 /// didn't actually change. |
| 51 void changeStatus(NodeStatus status) { | 54 void changeStatus(NodeStatus status) { |
| 52 if (_previousStatus != status) _onStatusChangeController.add(status); | 55 if (_previousStatus != status) _onStatusChangeController.add(status); |
| 53 } | 56 } |
| 54 | 57 |
| 55 /// Closes all the streams. | 58 /// Closes all the streams. |
| 56 void close() { | 59 void close() { |
| 57 _onStatusChangeController.close(); | 60 _onStatusChangeController.close(); |
| 58 onAssetController.close(); | 61 onAssetController.close(); |
| 59 onAssetPool.close(); | 62 onAssetPool.close(); |
| 60 onLogController.close(); | 63 onLogController.close(); |
| 61 onLogPool.close(); | 64 onLogPool.close(); |
| 62 } | 65 } |
| 63 } | 66 } |
| OLD | NEW |