OLD | NEW |
---|---|
(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 } | |
OLD | NEW |