Index: pkg/watcher/lib/src/utils.dart |
diff --git a/pkg/watcher/lib/src/utils.dart b/pkg/watcher/lib/src/utils.dart |
index a64575b9f796eab3536f792c95ea5c397822c20e..a235f7da5f2162004b309f1bd74f890636d6ab23 100644 |
--- a/pkg/watcher/lib/src/utils.dart |
+++ b/pkg/watcher/lib/src/utils.dart |
@@ -36,9 +36,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; |
}); |