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

Side by Side Diff: lib/src/backend/outstanding_callback_counter.dart

Issue 1116443002: Support future matchers and expectAsync in tearDowns. (Closed) Base URL: git@github.com:dart-lang/unittest.git@master
Patch Set: Created 5 years, 7 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
« no previous file with comments | « lib/src/backend/invoker.dart ('k') | lib/src/utils.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2015, 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 test.backend.outstanding_callback_counter;
6
7 import 'dart:async';
8
9 /// A class that counts outstanding callbacks for a test and fires a future once
10 /// they reach zero.
11 ///
12 /// The outstanding callback count automatically starts at 1.
13 class OutstandingCallbackCounter {
14 /// The number of outstanding callbacks.
15 var _count = 1;
kevmoo 2015/04/28 18:44:49 int!
nweiz 2015/04/28 18:56:18 It's private and its type is obvious from its init
16
17 /// A future that fires when the oustanding callback count reaches 0.
18 Future get noOutstandingCallbacks => _completer.future;
19 final _completer = new Completer();
20
21 /// Adds an outstanding callback.
22 void addOutstandingCallback() {
23 _count++;
24 }
25
26 /// Removes an outstanding callback.
27 void removeOutstandingCallback() {
28 _count--;
29 if (_count != 0) return;
30 if (_completer.isCompleted) return;
31 _completer.complete();
32 }
33
34 /// Removes all outstanding callbacks, forcing [noOutstandingCallbacks] to
35 /// fire.
36 ///
37 /// Future calls to [addOutstandingCallback] and [removeOutstandingCallback]
38 /// will be ignored.
39 void removeAllOutstandingCallbacks() {
40 if (!_completer.isCompleted) _completer.complete();
41 }
42 }
OLDNEW
« no previous file with comments | « lib/src/backend/invoker.dart ('k') | lib/src/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698