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

Bug a bug in StreamQueueTransaction.reject(). #22

Merged
merged 1 commit into from
Feb 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated comment: It's probably too late, but could we consider renaming reject to cancel? It's just so much more common, and it was the first name I looked for when I tried using the class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's probably too late. I'm not sure I like cancel anyway—in other contexts it usually refers to finalization and releasing of resources, whereas for a transaction it's much more part of the normal flow of usage.

await queue1.cancel();
Expand Down