bind method

  1. @override
StreamChannel<T> bind(
  1. StreamChannel<T> channel
)
override

Transforms the events sent to and emitted by channel.

Creates a new channel. When events are passed to the returned channel's sink, the transformer will transform them and pass the transformed versions to channel.sink. When events are emitted from the channel.straem, the transformer will transform them and pass the transformed versions to the returned channel's stream.

Implementation

@override
StreamChannel<T> bind(StreamChannel<T> channel) {
  return channel.changeSink((innerSink) {
    var sink = _DisconnectorSink<T>(innerSink);

    if (isDisconnected) {
      // Ignore errors here, because otherwise there would be no way for the
      // user to handle them gracefully.
      sink._disconnect().catchError((_) {});
    } else {
      _sinks.add(sink);
    }

    return sink;
  });
}