Index: pkg/scheduled_test/lib/src/utils.dart |
diff --git a/pkg/scheduled_test/lib/src/utils.dart b/pkg/scheduled_test/lib/src/utils.dart |
index 9a940cca8dd65b6d4a3f2b8c7e118f17c961be6d..2b8b78ef9e9dfd98143cdaacb6e75f88117ac809 100644 |
--- a/pkg/scheduled_test/lib/src/utils.dart |
+++ b/pkg/scheduled_test/lib/src/utils.dart |
@@ -91,9 +91,10 @@ Stream futureStream(Future<Stream> future, {bool broadcast: false}) { |
var controller; |
future = future.catchError((e, stackTrace) { |
- if (controller == null) return; |
- controller.addError(e, stackTrace); |
- controller.close(); |
+ // Since [controller] is synchronous, it's likely that emitting an error |
+ // will cause it to be cancelled before we call close. |
+ if (controller != null) controller.addError(e, stackTrace); |
+ if (controller != null) controller.close(); |
controller = null; |
}); |