Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1025)

Unified Diff: utils/pub/utils.dart

Issue 12225157: Work around issue 8512 in pub. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « utils/pub/error_group.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/pub/utils.dart
diff --git a/utils/pub/utils.dart b/utils/pub/utils.dart
index 729f55a0e0235380dad5be8198df6cbcc95ceb09..601290789e5dbbe1bdbf5cc3c257c307f5f54918 100644
--- a/utils/pub/utils.dart
+++ b/utils/pub/utils.dart
@@ -173,15 +173,25 @@ void chainToCompleter(Future future, Completer completer) {
/// Returns a [Future] that will complete to the first element of [stream].
/// Unlike [Stream.first], this is safe to use with single-subscription streams.
Future streamFirst(Stream stream) {
+ // TODO(nweiz): remove this when issue 8512 is fixed.
+ var cancelled = false;
var completer = new Completer();
var subscription;
subscription = stream.listen((value) {
- subscription.cancel();
- completer.complete(value);
- },
- onError: (e) => completer.completeError(e.error, e.stackTrace),
- onDone: () => completer.completeError(new StateError("No elements")),
- unsubscribeOnError: true);
+ if (!cancelled) {
+ cancelled = true;
+ subscription.cancel();
+ completer.complete(value);
+ }
+ }, onError: (e) {
+ if (!cancelled) {
+ completer.completeError(e.error, e.stackTrace);
+ }
+ }, onDone: () {
+ if (!cancelled) {
+ completer.completeError(new StateError("No elements"));
+ }
+ }, unsubscribeOnError: true);
return completer.future;
}
« no previous file with comments | « utils/pub/error_group.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698