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

Unified Diff: lib/src/stream_queue.dart

Issue 1223423002: Use a named param for StreamQueue.cancelImmediately. (Closed) Base URL: git@github.com:dart-lang/async.git@master
Patch Set: Code review changes Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/stream_queue_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/stream_queue.dart
diff --git a/lib/src/stream_queue.dart b/lib/src/stream_queue.dart
index 53ed1421758cdb33410f28e620bb2ed54787ada9..7d78ac593c79181bb504897f8f3b611130a3b48b 100644
--- a/lib/src/stream_queue.dart
+++ b/lib/src/stream_queue.dart
@@ -91,7 +91,7 @@ class StreamQueue<T> {
/// Whether a closing operation has been performed on the stream queue.
///
- /// Closing operations are [cancel], [cancelImmediately], and [rest].
+ /// Closing operations are [cancel] and [rest].
bool _isClosed = false;
/// Queue of events not used by a request yet.
@@ -218,9 +218,13 @@ class StreamQueue<T> {
/// Cancels the underlying stream subscription.
///
- /// The cancel operation waits until all previously requested
- /// events have been processed, then it cancels the subscription
- /// providing the events.
+ /// If [immediate] is `false` (the default), the cancel operation waits until
+ /// all previously requested events have been processed, then it cancels the
+ /// subscription providing the events.
+ ///
+ /// If [immediate] is `true`, the subscription is instead canceled
+ /// immediately. Any pending events are completed as though the underlying
+ /// stream had closed.
///
/// The returned future completes with the result of calling
/// `cancel`.
@@ -228,29 +232,15 @@ class StreamQueue<T> {
/// After calling `cancel`, no further events can be requested.
/// None of [next], [rest], [skip], [take] or [cancel] may be
/// called again.
- Future cancel() {
- if (!_isClosed) {
- _isClosed = true;
+ Future cancel({bool immediate: false}) {
+ if (_isClosed) throw _failClosed();
+ _isClosed = true;
+
+ if (!immediate) {
var request = new _CancelRequest(this);
_addRequest(request);
return request.future;
}
- throw _failClosed();
- }
-
- /// Cancels the underlying stream subscription immediately.
- ///
- /// Any pending events will complete as though the stream had closed when
- /// [cancel] was called.
- ///
- /// The returned future completes with the result of calling
- /// `StreamSubscription.cancel`.
- ///
- /// After calling `cancelImmediately`, no further events can be requested.
- /// None of [next], [rest], [skip], [take] or [cancel] may be called again.
- Future cancelImmediately() {
- if (_isClosed) throw _failClosed();
- _isClosed = true;
if (_isDone) return new Future.value();
if (_subscription == null) _subscription = _sourceStream.listen(null);
@@ -262,7 +252,7 @@ class StreamQueue<T> {
/// Returns an error for when a request is made after cancel.
///
/// Returns a [StateError] with a message saying that either
- /// [cancel], [cancelImmediately], or [rest] have already been called.
+ /// [cancel] or [rest] have already been called.
Error _failClosed() {
return new StateError("Already cancelled");
}
« no previous file with comments | « no previous file | test/stream_queue_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698