OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import 'dart:async'; | 5 import 'dart:async'; |
6 | 6 |
7 import 'result/capture_transformer.dart'; | 7 import 'result/capture_transformer.dart'; |
8 import 'result/error.dart'; | 8 import 'result/error.dart'; |
9 import 'result/release_transformer.dart'; | 9 import 'result/release_transformer.dart'; |
10 import 'result/value.dart'; | 10 import 'result/value.dart'; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 } | 83 } |
84 | 84 |
85 /// Release the result of a captured future. | 85 /// Release the result of a captured future. |
86 /// | 86 /// |
87 /// Converts the [Result] value of the given [future] to a value or error | 87 /// Converts the [Result] value of the given [future] to a value or error |
88 /// completion of the returned future. | 88 /// completion of the returned future. |
89 /// | 89 /// |
90 /// If [future] completes with an error, the returned future completes with | 90 /// If [future] completes with an error, the returned future completes with |
91 /// the same error. | 91 /// the same error. |
92 static Future<T> release<T>(Future<Result<T>> future) => | 92 static Future<T> release<T>(Future<Result<T>> future) => |
93 future.then<Future<T>>((result) => result.asFuture); | 93 future.then<T>((result) => result.asFuture); |
94 | 94 |
95 /// Capture the results of a stream into a stream of [Result] values. | 95 /// Capture the results of a stream into a stream of [Result] values. |
96 /// | 96 /// |
97 /// The returned stream will not have any error events. | 97 /// The returned stream will not have any error events. |
98 /// Errors from the source stream have been converted to [ErrorResult]s. | 98 /// Errors from the source stream have been converted to [ErrorResult]s. |
99 static Stream<Result<T>> captureStream<T>(Stream<T> source) => | 99 static Stream<Result<T>> captureStream<T>(Stream<T> source) => |
100 source.transform(new CaptureStreamTransformer<T>()); | 100 source.transform(new CaptureStreamTransformer<T>()); |
101 | 101 |
102 /// Release a stream of [result] values into a stream of the results. | 102 /// Release a stream of [result] values into a stream of the results. |
103 /// | 103 /// |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 void complete(Completer<T> completer); | 143 void complete(Completer<T> completer); |
144 | 144 |
145 /// Add this result to an [EventSink]. | 145 /// Add this result to an [EventSink]. |
146 /// | 146 /// |
147 /// Calls the sink's `add` or `addError` method as appropriate. | 147 /// Calls the sink's `add` or `addError` method as appropriate. |
148 void addTo(EventSink<T> sink); | 148 void addTo(EventSink<T> sink); |
149 | 149 |
150 /// Creates a future completed with this result as a value or an error. | 150 /// Creates a future completed with this result as a value or an error. |
151 Future<T> get asFuture; | 151 Future<T> get asFuture; |
152 } | 152 } |
OLD | NEW |