Rename concat as followedBy (dart-lang/stream_transform#43)
Matches the naming of `Iterable.followedBy`. Leave concat as a
deprecated alias.
Add .dart_tool to gitignore
diff --git a/pkgs/stream_transform/.gitignore b/pkgs/stream_transform/.gitignore
index 47f11e5..bfffcc6 100644
--- a/pkgs/stream_transform/.gitignore
+++ b/pkgs/stream_transform/.gitignore
@@ -1,4 +1,5 @@
.pub/
+.dart_tool/
build/
packages
pubspec.lock
diff --git a/pkgs/stream_transform/CHANGELOG.md b/pkgs/stream_transform/CHANGELOG.md
index fe8eaa2..0e0cfaa 100644
--- a/pkgs/stream_transform/CHANGELOG.md
+++ b/pkgs/stream_transform/CHANGELOG.md
@@ -1,3 +1,8 @@
+## 0.0.11
+
+- Renamed `concat` as `followedBy` to match the naming of `Iterable.followedBy`.
+ `concat` is now deprecated.
+
## 0.0.10
- Updates to support Dart 2.0 core library changes (wave
diff --git a/pkgs/stream_transform/README.md b/pkgs/stream_transform/README.md
index b504e6c..5e59fc9 100644
--- a/pkgs/stream_transform/README.md
+++ b/pkgs/stream_transform/README.md
@@ -19,15 +19,15 @@
Collects values from a source stream until a `trigger` stream fires and the
collected values are emitted.
-# concat
-
-Appends the values of a stream after another stream finishes.
-
# debounce, debounceBuffer
Prevents a source stream from emitting too frequently by dropping or collecting
values that occur within a given duration.
+# followedBy
+
+Appends the values of a stream after another stream finishes.
+
# merge, mergeAll
Interleaves events from multiple streams into a single stream.
diff --git a/pkgs/stream_transform/lib/src/concat.dart b/pkgs/stream_transform/lib/src/concat.dart
index bf0559d..565a290 100644
--- a/pkgs/stream_transform/lib/src/concat.dart
+++ b/pkgs/stream_transform/lib/src/concat.dart
@@ -1,86 +1,9 @@
-// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
+// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-
import 'dart:async';
-/// Starts emitting values from [next] after the original stream is complete.
-///
-/// If the initial stream never finishes, the [next] stream will never be
-/// listened to.
-///
-/// If a single-subscription is concatted to the end of a broadcast stream it
-/// may be listened to and never canceled.
-///
-/// If a broadcast stream is concatted to any other stream it will miss any
-/// events which occur before the first stream is done. If a broadcast stream is
-/// concatted to a single-subscription stream, pausing the stream while it is
-/// listening to the second stream will cause events to be dropped rather than
-/// buffered.
-StreamTransformer<T, T> concat<T>(Stream<T> next) => new _Concat<T>(next);
+import 'followed_by.dart';
-class _Concat<T> extends StreamTransformerBase<T, T> {
- final Stream<T> _next;
-
- _Concat(this._next);
-
- @override
- Stream<T> bind(Stream<T> first) {
- var controller = first.isBroadcast
- ? new StreamController<T>.broadcast(sync: true)
- : new StreamController<T>(sync: true);
-
- var next = first.isBroadcast && !_next.isBroadcast
- ? _next.asBroadcastStream()
- : _next;
-
- StreamSubscription subscription;
- var currentStream = first;
- var firstDone = false;
- var secondDone = false;
-
- Function currentDoneHandler;
-
- listen() {
- subscription = currentStream.listen(controller.add,
- onError: controller.addError, onDone: () => currentDoneHandler());
- }
-
- onSecondDone() {
- secondDone = true;
- controller.close();
- }
-
- onFirstDone() {
- firstDone = true;
- currentStream = next;
- currentDoneHandler = onSecondDone;
- listen();
- }
-
- currentDoneHandler = onFirstDone;
-
- controller.onListen = () {
- if (subscription != null) return;
- listen();
- if (!first.isBroadcast) {
- controller.onPause = () {
- if (!firstDone || !next.isBroadcast) return subscription.pause();
- subscription.cancel();
- subscription = null;
- };
- controller.onResume = () {
- if (!firstDone || !next.isBroadcast) return subscription.resume();
- listen();
- };
- }
- controller.onCancel = () {
- if (secondDone) return null;
- var toCancel = subscription;
- subscription = null;
- return toCancel.cancel();
- };
- };
- return controller.stream;
- }
-}
+@Deprecated('Use followedBy instead')
+StreamTransformer<T, T> concat<T>(Stream<T> next) => followedBy<T>(next);
diff --git a/pkgs/stream_transform/lib/src/followed_by.dart b/pkgs/stream_transform/lib/src/followed_by.dart
new file mode 100644
index 0000000..22f6945
--- /dev/null
+++ b/pkgs/stream_transform/lib/src/followed_by.dart
@@ -0,0 +1,86 @@
+// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'dart:async';
+
+/// Starts emitting values from [next] after the original stream is complete.
+///
+/// If the initial stream never finishes, the [next] stream will never be
+/// listened to.
+///
+/// If a single-subscription follows the a broadcast stream it may be listened
+/// to and never canceled.
+///
+/// If a broadcast stream follows any other stream it will miss any events which
+/// occur before the first stream is done. If a broadcast stream follows a
+/// single-subscription stream, pausing the stream while it is listening to the
+/// second stream will cause events to be dropped rather than buffered.
+StreamTransformer<T, T> followedBy<T>(Stream<T> next) =>
+ new _FollowedBy<T>(next);
+
+class _FollowedBy<T> extends StreamTransformerBase<T, T> {
+ final Stream<T> _next;
+
+ _FollowedBy(this._next);
+
+ @override
+ Stream<T> bind(Stream<T> first) {
+ var controller = first.isBroadcast
+ ? new StreamController<T>.broadcast(sync: true)
+ : new StreamController<T>(sync: true);
+
+ var next = first.isBroadcast && !_next.isBroadcast
+ ? _next.asBroadcastStream()
+ : _next;
+
+ StreamSubscription subscription;
+ var currentStream = first;
+ var firstDone = false;
+ var secondDone = false;
+
+ Function currentDoneHandler;
+
+ listen() {
+ subscription = currentStream.listen(controller.add,
+ onError: controller.addError, onDone: () => currentDoneHandler());
+ }
+
+ onSecondDone() {
+ secondDone = true;
+ controller.close();
+ }
+
+ onFirstDone() {
+ firstDone = true;
+ currentStream = next;
+ currentDoneHandler = onSecondDone;
+ listen();
+ }
+
+ currentDoneHandler = onFirstDone;
+
+ controller.onListen = () {
+ if (subscription != null) return;
+ listen();
+ if (!first.isBroadcast) {
+ controller.onPause = () {
+ if (!firstDone || !next.isBroadcast) return subscription.pause();
+ subscription.cancel();
+ subscription = null;
+ };
+ controller.onResume = () {
+ if (!firstDone || !next.isBroadcast) return subscription.resume();
+ listen();
+ };
+ }
+ controller.onCancel = () {
+ if (secondDone) return null;
+ var toCancel = subscription;
+ subscription = null;
+ return toCancel.cancel();
+ };
+ };
+ return controller.stream;
+ }
+}
diff --git a/pkgs/stream_transform/lib/stream_transform.dart b/pkgs/stream_transform/lib/stream_transform.dart
index dced908..170a5be 100644
--- a/pkgs/stream_transform/lib/stream_transform.dart
+++ b/pkgs/stream_transform/lib/stream_transform.dart
@@ -8,6 +8,7 @@
export 'src/buffer.dart';
export 'src/concat.dart';
export 'src/debounce.dart';
+export 'src/followed_by.dart';
export 'src/merge.dart';
export 'src/scan.dart';
export 'src/start_with.dart';
diff --git a/pkgs/stream_transform/pubspec.yaml b/pkgs/stream_transform/pubspec.yaml
index 06d650d..7087b00 100644
--- a/pkgs/stream_transform/pubspec.yaml
+++ b/pkgs/stream_transform/pubspec.yaml
@@ -2,7 +2,7 @@
description: A collection of utilities to transform and manipulate streams.
author: Dart Team <misc@dartlang.org>
homepage: https://www.github.com/dart-lang/stream_transform
-version: 0.0.10
+version: 0.0.11
environment:
sdk: ">=2.0.0-dev.20.0 <2.0.0"
diff --git a/pkgs/stream_transform/test/concat_test.dart b/pkgs/stream_transform/test/followd_by_test.dart
similarity index 100%
rename from pkgs/stream_transform/test/concat_test.dart
rename to pkgs/stream_transform/test/followd_by_test.dart