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

Unified Diff: quiver/lib/src/async/future_group.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 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 | « quiver/lib/src/async/countdown_timer.dart ('k') | quiver/lib/src/async/future_stream.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: quiver/lib/src/async/future_group.dart
diff --git a/quiver/lib/src/async/future_group.dart b/quiver/lib/src/async/future_group.dart
deleted file mode 100644
index c96ee1a3b7d525116bfa8d6e8d678d862888838f..0000000000000000000000000000000000000000
--- a/quiver/lib/src/async/future_group.dart
+++ /dev/null
@@ -1,74 +0,0 @@
-// Copyright 2013 Google Inc. All Rights Reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-part of quiver.async;
-
-/**
- * A collection of [Future]s that signals when all added Futures complete. New
- * Futures can be added to the group as long as it hasn't completed.
- *
- * FutureGroup is useful for managing a set of async tasks that may spawn new
- * async tasks as they execute.
- */
-class FutureGroup<E> {
- static const _FINISHED = -1;
-
- int _pending = 0;
- Future _failedTask;
- final Completer<List> _completer = new Completer<List>();
- final List results = [];
-
- /** Gets the task that failed, if any. */
- Future get failedTask => _failedTask;
-
- /**
- * Wait for [task] to complete.
- *
- * If this group has already been marked as completed, a [StateError] will be
- * thrown.
- *
- * If this group has a [failedTask], new tasks will be ignored, because the
- * error has already been signaled.
- */
- void add(Future task) {
- if (_failedTask != null) return;
- if (_pending == _FINISHED) throw new StateError("Future already completed");
-
- _pending++;
- var i = results.length;
- results.add(null);
- task.then((res) {
- results[i] = res;
- if (_failedTask != null) return;
- _pending--;
- if (_pending == 0) {
- _pending = _FINISHED;
- _completer.complete(results);
- }
- }, onError: (e, s) {
- if (_failedTask != null) return;
- _failedTask = task;
- _completer.completeError(e, s);
- });
- }
-
- /**
- * A Future that complets with a List of the values from all the added
- * tasks, when they have all completed.
- *
- * If any task fails, this Future will receive the error. Only the first
- * error will be sent to the Future.
- */
- Future<List<E>> get future => _completer.future;
-}
« no previous file with comments | « quiver/lib/src/async/countdown_timer.dart ('k') | quiver/lib/src/async/future_stream.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698