LCOV - code coverage report
Current view: top level - test-0.12.24+8/lib/src/backend - outstanding_callback_counter.dart (source / functions) Hit Total Coverage
Test: coverage.lcov Lines: 5 7 71.4 %
Date: 2017-10-10 20:17:03 Functions: 0 0 -

          Line data    Source code
       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             : import 'dart:async';
       6             : 
       7             : /// A class that counts outstanding callbacks for a test and fires a future once
       8             : /// they reach zero.
       9             : ///
      10             : /// The outstanding callback count automatically starts at 1.
      11             : class OutstandingCallbackCounter {
      12             :   /// The number of outstanding callbacks.
      13             :   var _count = 1;
      14             : 
      15             :   /// A future that fires when the oustanding callback count reaches 0.
      16          10 :   Future get noOutstandingCallbacks => _completer.future;
      17             :   final _completer = new Completer();
      18             : 
      19             :   /// Adds an outstanding callback.
      20             :   void addOutstandingCallback() {
      21           0 :     _count++;
      22             :   }
      23             : 
      24             :   /// Removes an outstanding callback.
      25             :   void removeOutstandingCallback() {
      26          10 :     _count--;
      27          10 :     if (_count != 0) return;
      28          10 :     if (_completer.isCompleted) return;
      29          10 :     _completer.complete();
      30             :   }
      31             : 
      32             :   /// Removes all outstanding callbacks, forcing [noOutstandingCallbacks] to
      33             :   /// fire.
      34             :   ///
      35             :   /// Future calls to [addOutstandingCallback] and [removeOutstandingCallback]
      36             :   /// will be ignored.
      37             :   void removeAllOutstandingCallbacks() {
      38           0 :     if (!_completer.isCompleted) _completer.complete();
      39             :   }
      40             : }

Generated by: LCOV version 1.13