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

Unified Diff: packages/async/lib/src/delegate/future.dart

Issue 2989763002: Update charted to 0.4.8 and roll (Closed)
Patch Set: Removed Cutch from list of reviewers Created 3 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « packages/async/lib/src/delegate/event_sink.dart ('k') | packages/async/lib/src/delegate/sink.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packages/async/lib/src/delegate/future.dart
diff --git a/packages/async/lib/src/delegate/future.dart b/packages/async/lib/src/delegate/future.dart
index 34f615892a09d386275c0c62004349ebce885565..129ad49d1238978635ee8610051dbf3dc104480c 100644
--- a/packages/async/lib/src/delegate/future.dart
+++ b/packages/async/lib/src/delegate/future.dart
@@ -2,27 +2,36 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-library async.delegate.future;
-
import 'dart:async';
+import '../typed/future.dart';
+
/// A wrapper that forwards calls to a [Future].
class DelegatingFuture<T> implements Future<T> {
/// The wrapped [Future].
- final Future _future;
+ final Future<T> _future;
DelegatingFuture(this._future);
+ /// Creates a wrapper which throws if [future]'s value isn't an instance of
+ /// `T`.
+ ///
+ /// This soundly converts a [Future] to a `Future<T>`, regardless of its
+ /// original generic type, by asserting that its value is an instance of `T`
+ /// whenever it's provided. If it's not, the future throws a [CastError].
+ static Future<T> typed<T>(Future future) =>
+ future is Future<T> ? future : new TypeSafeFuture<T>(future);
+
Stream<T> asStream() => _future.asStream();
- Future catchError(Function onError, {bool test(error)}) =>
- _future.catchError(onError, test: test);
+ Future<T> catchError(Function onError, {bool test(Object error)}) =>
+ _future.catchError(onError, test: test);
- Future then(onValue(T value), {Function onError}) =>
- _future.then(onValue, onError: onError);
+ Future<S> then<S>(FutureOr<S> onValue(T value), {Function onError}) =>
+ _future.then(onValue, onError: onError);
Future<T> whenComplete(action()) => _future.whenComplete(action);
- Future timeout(Duration timeLimit, {void onTimeout()}) =>
- _future.timeout(timeLimit, onTimeout: onTimeout);
+ Future<T> timeout(Duration timeLimit, {onTimeout()}) =>
+ _future.timeout(timeLimit, onTimeout: onTimeout);
}
« no previous file with comments | « packages/async/lib/src/delegate/event_sink.dart ('k') | packages/async/lib/src/delegate/sink.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698