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

Side by Side Diff: pkg/scheduled_test/lib/src/future_group.dart

Issue 12288061: Support nested tasks in scheduled_test. (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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 library future_group;
6
7 import 'dart:async';
8
9 /// A completer that waits until all added [Future]s complete.
10 // TODO(rnystrom): Copied from web_components. Remove from here when it gets
11 // added to dart:core. (See #6626.)
12 class FutureGroup<T> {
13 int _pending = 0;
14 Completer<List<T>> _completer = new Completer<List<T>>();
15 final List<Future<T>> futures = <Future<T>>[];
Bob Nystrom 2013/02/19 23:15:04 Is there a reason to store these?
nweiz 2013/02/20 00:23:12 I don't want to change this code here without chan
16 bool completed = false;
17
18 final List<T> _values = <T>[];
19
20 /// Wait for [task] to complete.
21 Future<T> add(Future<T> task) {
22 if (completed) {
23 throw new StateError("The FutureGroup has already completed.");
24 }
25
26 _pending++;
27 futures.add(task.then((value) {
28 if (completed) return;
Bob Nystrom 2013/02/19 23:15:04 It seems weird to swallow this. Doesn't this indic
nweiz 2013/02/20 00:23:12 In this code, the futures passed to FutureGroup ar
29
30 _pending--;
31 _values.add(value);
32
33 if (_pending <= 0) {
34 completed = true;
35 _completer.complete(_values);
36 }
37 }).catchError((e) {
38 if (completed) return;
Bob Nystrom 2013/02/19 23:15:04 Ditto here.
39
40 completed = true;
Bob Nystrom 2013/02/19 23:15:04 It seems like every place we use a completer we en
nweiz 2013/02/20 00:23:12 Filed as issue 8638.
41 _completer.completeError(e.error, e.stackTrace);
42 }));
43
44 return task;
45 }
46
47 Future<List> get future => _completer.future;
48 }
49
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698