| 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.dart'; | 7 import 'result.dart'; |
| 8 | 8 |
| 9 /// Use [Result.captureSinkTransformer]. | 9 /// Used by [Result.releaseSink]. |
| 10 @Deprecated("Will be removed in async 2.0.0.") | |
| 11 class ReleaseSink<T> implements EventSink<Result<T>> { | 10 class ReleaseSink<T> implements EventSink<Result<T>> { |
| 12 final EventSink _sink; | 11 final EventSink _sink; |
| 13 | 12 |
| 14 ReleaseSink(EventSink<T> sink) : _sink = sink; | 13 ReleaseSink(EventSink<T> sink) : _sink = sink; |
| 15 | 14 |
| 16 void add(Result<T> result) { | 15 void add(Result<T> result) { |
| 17 if (result.isValue) { | 16 result.addTo(_sink); |
| 18 _sink.add(result.asValue.value); | |
| 19 } else { | |
| 20 var error = result.asError; | |
| 21 _sink.addError(error.error, error.stackTrace); | |
| 22 } | |
| 23 } | 17 } |
| 24 | 18 |
| 25 void addError(Object error, [StackTrace stackTrace]) { | 19 void addError(Object error, [StackTrace stackTrace]) { |
| 26 // Errors may be added by intermediate processing, even if it is never | 20 // Errors may be added by intermediate processing, even if it is never |
| 27 // added by CaptureSink. | 21 // added by CaptureSink. |
| 28 _sink.addError(error, stackTrace); | 22 _sink.addError(error, stackTrace); |
| 29 } | 23 } |
| 30 | 24 |
| 31 void close() { | 25 void close() { |
| 32 _sink.close(); | 26 _sink.close(); |
| 33 } | 27 } |
| 34 } | 28 } |
| OLD | NEW |