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

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

Issue 98683002: Change other futures to also have timeout take a named parameter. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years 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
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 substitute_future; 5 library substitute_future;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 /// A wrapper for [Future] that allows other [Future]s to be substituted in as 9 /// A wrapper for [Future] that allows other [Future]s to be substituted in as
10 /// the wrapped [Future]. This is used for injecting timeout errors into 10 /// the wrapped [Future]. This is used for injecting timeout errors into
(...skipping 11 matching lines...) Expand all
22 SubstituteFuture(Future wrapped) { 22 SubstituteFuture(Future wrapped) {
23 substitute(wrapped); 23 substitute(wrapped);
24 } 24 }
25 25
26 Stream<T> asStream() => _completer.future.asStream(); 26 Stream<T> asStream() => _completer.future.asStream();
27 Future catchError(Function onError, {bool test(error)}) => 27 Future catchError(Function onError, {bool test(error)}) =>
28 _completer.future.catchError(onError, test: test); 28 _completer.future.catchError(onError, test: test);
29 Future then(onValue(T value), {Function onError}) => 29 Future then(onValue(T value), {Function onError}) =>
30 _completer.future.then(onValue, onError: onError); 30 _completer.future.then(onValue, onError: onError);
31 Future<T> whenComplete(action()) => _completer.future.whenComplete(action); 31 Future<T> whenComplete(action()) => _completer.future.whenComplete(action);
32 Future timeout(Duration timeLimit, [void onTimeout()]) => 32 Future timeout(Duration timeLimit, {void onTimeout()}) =>
33 _completer.future.timeout(timeLimit, onTimeout); 33 _completer.future.timeout(timeLimit, onTimeout: onTimeout);
34 34
35 /// Substitutes [newFuture] for the currently wrapped [Future], which is 35 /// Substitutes [newFuture] for the currently wrapped [Future], which is
36 /// returned. 36 /// returned.
37 Future<T> substitute(Future<T> newFuture) { 37 Future<T> substitute(Future<T> newFuture) {
38 if (_complete) { 38 if (_complete) {
39 throw new StateError("You may not call substitute on a SubstituteFuture " 39 throw new StateError("You may not call substitute on a SubstituteFuture "
40 "that's already complete."); 40 "that's already complete.");
41 } 41 }
42 42
43 var oldFuture = _inner; 43 var oldFuture = _inner;
44 _inner = newFuture; 44 _inner = newFuture;
45 _inner.then((value) { 45 _inner.then((value) {
46 if (_inner != newFuture) return; 46 if (_inner != newFuture) return;
47 _completer.complete(value); 47 _completer.complete(value);
48 _complete = true; 48 _complete = true;
49 }).catchError((error, stackTrace) { 49 }).catchError((error, stackTrace) {
50 if (_inner != newFuture) return; 50 if (_inner != newFuture) return;
51 _completer.completeError(error, stackTrace); 51 _completer.completeError(error, stackTrace);
52 _complete = true; 52 _complete = true;
53 }); 53 });
54 return oldFuture; 54 return oldFuture;
55 } 55 }
56 } 56 }
OLDNEW
« no previous file with comments | « pkg/barback/lib/src/cancelable_future.dart ('k') | pkg/scheduled_test/lib/src/value_future.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698