Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
Bug a bug in StreamQueueTransaction.reject(). (#22)
Browse files Browse the repository at this point in the history
This would throw a StateError if StreamQueue.rest had been called on
one of the transaction's child queues, because that queue didn't expect
to be canceled later on.
  • Loading branch information
nex3 authored Feb 2, 2017
1 parent 420d084 commit 6dbf465
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* Add a `collectBytes` function which collects list-of-byte events into
a single byte list.

* Fix a bug where rejecting a `StreamQueueTransaction` would throw a
`StateError` if `StreamQueue.rest` had been called on one of its child queues.

## 1.12.0

* Add an `AsyncCache` class that caches asynchronous operations for a period of
Expand Down
4 changes: 2 additions & 2 deletions lib/src/stream_queue.dart
Original file line number Diff line number Diff line change
Expand Up @@ -548,14 +548,14 @@ class _StreamQueue<T> extends StreamQueue<T> {
if (_isDone) {
return new Stream<T>.empty();
}
_isDone = true;

if (_subscription == null) {
return _sourceStream;
}

var subscription = _subscription;
_subscription = null;
_isDone = true;

var wasPaused = subscription.isPaused;
var result = new SubscriptionStream<T>(subscription);
Expand Down Expand Up @@ -960,7 +960,7 @@ class _HasNextRequest<T> implements _EventRequest<T> {
/// Request for a [StreamQueue.startTransaction] call.
///
/// This request isn't complete until the user calls
/// [StreamQueueTransaction.commit] or [StreamQueue.rejectTransaction], at which
/// [StreamQueueTransaction.commit] or [StreamQueueTransaction.reject], at which
/// point it manually removes itself from the request queue and calls
/// [StreamQueue._updateRequests].
class _TransactionRequest<T> implements _EventRequest<T> {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: async
version: 1.13.0
version: 1.13.0-dev
author: Dart Team <misc@dartlang.org>
description: Utility functions and classes related to the 'dart:async' library.
homepage: https://www.github.com/dart-lang/async
Expand Down
24 changes: 24 additions & 0 deletions test/stream_queue_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,30 @@ main() {
transaction.reject();
});

// Regression test.
test("pending child rest requests emit no more events", () async {
var controller = new StreamController();
var events = new StreamQueue(controller.stream);
var transaction = events.startTransaction();
var queue = transaction.newQueue();

// This should emit no more events after the transaction is rejected.
queue.rest.listen(expectAsync1((_) {}, count: 3),
onDone: expectAsync0(() {}, count: 0));

controller.add(1);
controller.add(2);
controller.add(3);
await flushMicrotasks();

transaction.reject();
await flushMicrotasks();

// These shouldn't affect the result of `queue.rest.toList()`.
controller.add(4);
controller.add(5);
});

test("child requests' cancel() may still be called explicitly", () async {
transaction.reject();
await queue1.cancel();
Expand Down

0 comments on commit 6dbf465

Please sign in to comment.