OLD | NEW |
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.utils; | 5 library barback.utils; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:typed_data'; | 8 import 'dart:typed_data'; |
9 | 9 |
10 import 'package:stack_trace/stack_trace.dart'; | 10 import 'package:stack_trace/stack_trace.dart'; |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 subscription = callback().listen(controller.add, | 301 subscription = callback().listen(controller.add, |
302 onError: controller.addError, | 302 onError: controller.addError, |
303 onDone: controller.close); | 303 onDone: controller.close); |
304 }, | 304 }, |
305 onCancel: () => subscription.cancel(), | 305 onCancel: () => subscription.cancel(), |
306 onPause: () => subscription.pause(), | 306 onPause: () => subscription.pause(), |
307 onResume: () => subscription.resume(), | 307 onResume: () => subscription.resume(), |
308 sync: true); | 308 sync: true); |
309 return controller.stream; | 309 return controller.stream; |
310 } | 310 } |
311 | |
312 /// Creates a single-subscription stream from a broadcast stream. | |
313 /// | |
314 /// The returned stream will enqueue events from [broadcast] until a listener is | |
315 /// attached, then pipe events to that listener. | |
316 Stream broadcastToSingleSubscription(Stream broadcast) { | |
317 if (!broadcast.isBroadcast) return broadcast; | |
318 | |
319 // TODO(nweiz): Implement this using a transformer when issues 18588 and 18586 | |
320 // are fixed. | |
321 var subscription; | |
322 var controller = new StreamController(onCancel: () => subscription.cancel()); | |
323 subscription = broadcast.listen(controller.add, | |
324 onError: controller.addError, | |
325 onDone: controller.close); | |
326 return controller.stream; | |
327 } | |
OLD | NEW |