Line data Source code
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 3 : // BSD-style license that can be found in the LICENSE file. 4 : 5 : import 'dart:async'; 6 : 7 : import 'result.dart'; 8 : 9 : /// Used by [Result.captureSink]. 10 : class CaptureSink<T> implements EventSink<T> { 11 : final EventSink<Result<T>> _sink; 12 : 13 0 : CaptureSink(EventSink<Result<T>> sink) : _sink = sink; 14 : 15 0 : @override 16 : void add(T value) { 17 0 : _sink.add(Result<T>.value(value)); 18 : } 19 : 20 0 : @override 21 : void addError(Object error, [StackTrace? stackTrace]) { 22 0 : _sink.add(Result.error(error, stackTrace)); 23 : } 24 : 25 0 : @override 26 : void close() { 27 0 : _sink.close(); 28 : } 29 : }