From 878d8103349b18217fbc57ee5e6bed0f39e0eb29 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Mon, 6 Feb 2017 15:40:29 -0800 Subject: [PATCH] Fix StreamQueue.withTransaction(). (#24) --- CHANGELOG.md | 3 +++ lib/src/stream_queue.dart | 1 + test/stream_queue_test.dart | 5 +++++ 3 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index adf53c7..5685503 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ * Fix a bug where rejecting a `StreamQueueTransaction` would throw a `StateError` if `StreamQueue.rest` had been called on one of its child queues. +* `StreamQueue.withTransaction()` now properly returns whether or not the + transaction was committed. + ## 1.12.0 * Add an `AsyncCache` class that caches asynchronous operations for a period of diff --git a/lib/src/stream_queue.dart b/lib/src/stream_queue.dart index 575cc8a..99e7436 100644 --- a/lib/src/stream_queue.dart +++ b/lib/src/stream_queue.dart @@ -328,6 +328,7 @@ abstract class StreamQueue { } else { transaction.reject(); } + return result; }, onError: (error) { transaction.commit(queue); throw error; diff --git a/test/stream_queue_test.dart b/test/stream_queue_test.dart index 7d2fdd4..f487e65 100644 --- a/test/stream_queue_test.dart +++ b/test/stream_queue_test.dart @@ -1004,6 +1004,11 @@ main() { expect(events.next, completion(3)); }); + + test("returns whether the transaction succeeded", () { + expect(events.withTransaction((_) async => true), completion(isTrue)); + expect(events.withTransaction((_) async => false), completion(isFalse)); + }); }); group("cancelable operation", () {