LCOV - code coverage report
Current view: top level - async-2.5.0/lib/src/stream_sink_transformer - stream_transformer_wrapper.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 1 19 5.3 %
Date: 2021-11-28 14:37:50 Functions: 0 0 -

          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 '../stream_sink_transformer.dart';
       8             : 
       9             : /// A [StreamSinkTransformer] that wraps a pre-existing [StreamTransformer].
      10             : class StreamTransformerWrapper<S, T> implements StreamSinkTransformer<S, T> {
      11             :   /// The wrapped transformer.
      12             :   final StreamTransformer<S, T> _transformer;
      13             : 
      14          11 :   const StreamTransformerWrapper(this._transformer);
      15             : 
      16           0 :   @override
      17             :   StreamSink<S> bind(StreamSink<T> sink) =>
      18           0 :       _StreamTransformerWrapperSink<S, T>(_transformer, sink);
      19             : }
      20             : 
      21             : /// A sink created by [StreamTransformerWrapper].
      22             : class _StreamTransformerWrapperSink<S, T> implements StreamSink<S> {
      23             :   /// The controller through which events are passed.
      24             :   ///
      25             :   /// This is used to create a stream that can be transformed by the wrapped
      26             :   /// transformer.
      27             :   final _controller = StreamController<S>(sync: true);
      28             : 
      29             :   /// The original sink that's being transformed.
      30             :   final StreamSink<T> _inner;
      31             : 
      32           0 :   @override
      33           0 :   Future get done => _inner.done;
      34             : 
      35           0 :   _StreamTransformerWrapperSink(
      36             :       StreamTransformer<S, T> transformer, this._inner) {
      37           0 :     _controller.stream
      38           0 :         .transform(transformer)
      39           0 :         .listen(_inner.add, onError: _inner.addError, onDone: () {
      40             :       // Ignore any errors that come from this call to [_inner.close]. The
      41             :       // user can access them through [done] or the value returned from
      42             :       // [this.close], and we don't want them to get top-leveled.
      43           0 :       _inner.close().catchError((_) {});
      44             :     });
      45             :   }
      46             : 
      47           0 :   @override
      48             :   void add(S event) {
      49           0 :     _controller.add(event);
      50             :   }
      51             : 
      52           0 :   @override
      53             :   void addError(error, [StackTrace? stackTrace]) {
      54           0 :     _controller.addError(error, stackTrace);
      55             :   }
      56             : 
      57           0 :   @override
      58           0 :   Future addStream(Stream<S> stream) => _controller.addStream(stream);
      59             : 
      60           0 :   @override
      61             :   Future close() {
      62           0 :     _controller.close();
      63           0 :     return _inner.done;
      64             :   }
      65             : }

Generated by: LCOV version 1.14