From 8d6b6f7340ae7078f171720aa3a7e6bd0fd37e73 Mon Sep 17 00:00:00 2001 From: Petrus Nguyen Thai Hoc Date: Mon, 8 Feb 2021 18:18:03 +0700 Subject: [PATCH] fix ignore.dart --- lib/src/ignore.dart | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/src/ignore.dart b/lib/src/ignore.dart index 8bd5216..bbc6fee 100644 --- a/lib/src/ignore.dart +++ b/lib/src/ignore.dart @@ -2,30 +2,32 @@ import 'dart:async'; import 'default_sink.dart'; -/// Ignore all data events, forward error and done event. +class _IgnoreElementsStreamSink + with ForwardingSinkMixin + implements ForwardingSink { + @override + void add(EventSink sink, T data) {} +} + +/// Ignore all data events, forward only error and done event. extension IgnoreElementStreamExtension on Stream { - /// Ignore all data events, forward error and done event. - Stream ignoreElements() { - return transform( - StreamTransformer.fromHandlers( - handleData: (_, sink) {}, - ), - ); - } + /// Ignore all data events, forward only error and done event. + Stream ignoreElements() => + forwardStream(this, _IgnoreElementsStreamSink()); } class _IgnoreErrorsStreamSink with ForwardingSinkMixin implements ForwardingSink { @override - void add(EventSink sink, T data) {} + void add(EventSink sink, T data) => sink.add(data); @override void addError(EventSink sink, Object error, [StackTrace? st]) {} } -/// Ignore all error events, forward data and done event. +/// Ignore all error events, forward only data and done event. extension IgnoreErrorsStreamExtension on Stream { - /// Ignore all error events, forward data and done event. + /// Ignore all error events, forward only data and done event. Stream ignoreErrors() => forwardStream(this, _IgnoreErrorsStreamSink()); }