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

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

Issue 25094002: Adapt streams for additional stackTrace argument. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 2 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
OLDNEW
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 barback.stream_replayer; 5 library barback.stream_replayer;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'utils.dart'; 10 import 'utils.dart';
(...skipping 16 matching lines...) Expand all
27 27
28 /// The controllers that are listening for future events from [_stream]. 28 /// The controllers that are listening for future events from [_stream].
29 final _controllers = new Set<StreamController<T>>(); 29 final _controllers = new Set<StreamController<T>>();
30 30
31 StreamReplayer(this._stream) { 31 StreamReplayer(this._stream) {
32 _stream.listen((data) { 32 _stream.listen((data) {
33 _buffer.add(new Either<T, dynamic>.withFirst(data)); 33 _buffer.add(new Either<T, dynamic>.withFirst(data));
34 for (var controller in _controllers) { 34 for (var controller in _controllers) {
35 controller.add(data); 35 controller.add(data);
36 } 36 }
37 }, onError: (error) { 37 }, onError: (error, [StackTrace stackTrace]) {
nweiz 2013/10/07 18:49:51 [_buffer] now needs to track the stack trace along
floitsch 2013/10/10 14:22:52 Done.
38 _buffer.add(new Either<T, dynamic>.withSecond(error)); 38 _buffer.add(new Either<T, dynamic>.withSecond(error));
39 for (var controller in _controllers) { 39 for (var controller in _controllers) {
40 controller.addError(error); 40 controller.addError(error, stackTrace);
41 } 41 }
42 }, onDone: () { 42 }, onDone: () {
43 _isClosed = true; 43 _isClosed = true;
44 for (var controller in _controllers) { 44 for (var controller in _controllers) {
45 controller.close(); 45 controller.close();
46 } 46 }
47 _controllers.clear(); 47 _controllers.clear();
48 }); 48 });
49 } 49 }
50 50
51 /// Returns a stream that replays the values and errors of the input stream. 51 /// Returns a stream that replays the values and errors of the input stream.
52 /// 52 ///
53 /// This stream is a buffered stream regardless of whether the input stream 53 /// This stream is a buffered stream regardless of whether the input stream
54 /// was broadcast or buffered. 54 /// was broadcast or buffered.
55 Stream<T> getReplay() { 55 Stream<T> getReplay() {
56 var controller = new StreamController<T>(); 56 var controller = new StreamController<T>();
57 for (var eventOrError in _buffer) { 57 for (var eventOrError in _buffer) {
58 eventOrError.match(controller.add, controller.addError); 58 eventOrError.match(controller.add, controller.addError);
59 } 59 }
60 if (_isClosed) { 60 if (_isClosed) {
61 controller.close(); 61 controller.close();
62 } else { 62 } else {
63 _controllers.add(controller); 63 _controllers.add(controller);
64 } 64 }
65 return controller.stream; 65 return controller.stream;
66 } 66 }
67 } 67 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698