OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library test_utils; | 5 library test_utils; |
6 | 6 |
7 import 'dart:io'; | 7 import 'dart:io'; |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 | 9 |
10 import '../lib/src/utils.dart'; | 10 import 'package:scheduled_test/src/utils.dart'; |
11 import '../lib/src/mock_clock.dart' as mock_clock; | 11 import 'package:scheduled_test/src/mock_clock.dart' as mock_clock; |
12 | 12 |
13 export '../lib/src/utils.dart'; | 13 export 'package:scheduled_test/src/utils.dart'; |
14 | 14 |
15 /// Wraps [input] to provide a timeout. If [input] completes before | 15 /// Wraps [input] to provide a timeout. If [input] completes before |
16 /// [milliseconds] have passed, then the return value completes in the same way. | 16 /// [milliseconds] have passed, then the return value completes in the same way. |
17 /// However, if [milliseconds] pass before [input] has completed, [onTimeout] is | 17 /// However, if [milliseconds] pass before [input] has completed, [onTimeout] is |
18 /// run and its result is passed to [input] (with chaining, if it returns a | 18 /// run and its result is passed to [input] (with chaining, if it returns a |
19 /// [Future]). | 19 /// [Future]). |
20 /// | 20 /// |
21 /// Note that timing out will not cancel the asynchronous operation behind | 21 /// Note that timing out will not cancel the asynchronous operation behind |
22 /// [input]. | 22 /// [input]. |
23 Future timeout(Future input, int milliseconds, onTimeout()) { | 23 Future timeout(Future input, int milliseconds, onTimeout()) { |
(...skipping 14 matching lines...) Expand all Loading... |
38 } | 38 } |
39 | 39 |
40 /// Returns a [Future] that will complete in [milliseconds]. | 40 /// Returns a [Future] that will complete in [milliseconds]. |
41 Future sleep(int milliseconds) { | 41 Future sleep(int milliseconds) { |
42 var completer = new Completer(); | 42 var completer = new Completer(); |
43 mock_clock.newTimer(new Duration(milliseconds: milliseconds), () { | 43 mock_clock.newTimer(new Duration(milliseconds: milliseconds), () { |
44 completer.complete(); | 44 completer.complete(); |
45 }); | 45 }); |
46 return completer.future; | 46 return completer.future; |
47 } | 47 } |
OLD | NEW |