Skip to content

Commit

Permalink
fix ignore.dart
Browse files Browse the repository at this point in the history
  • Loading branch information
hoc081098 committed Feb 8, 2021
1 parent bf98422 commit 8d6b6f7
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions lib/src/ignore.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,32 @@ import 'dart:async';

import 'default_sink.dart';

/// Ignore all data events, forward error and done event.
class _IgnoreElementsStreamSink<T>
with ForwardingSinkMixin<T, T>
implements ForwardingSink<T, T> {
@override
void add(EventSink<T> sink, T data) {}
}

/// Ignore all data events, forward only error and done event.
extension IgnoreElementStreamExtension<T> on Stream<T> {
/// Ignore all data events, forward error and done event.
Stream<R> ignoreElements<R>() {
return transform<R>(
StreamTransformer.fromHandlers(
handleData: (_, sink) {},
),
);
}
/// Ignore all data events, forward only error and done event.
Stream<R> ignoreElements<R>() =>
forwardStream(this, _IgnoreElementsStreamSink());
}

class _IgnoreErrorsStreamSink<T>
with ForwardingSinkMixin<T, T>
implements ForwardingSink<T, T> {
@override
void add(EventSink<T> sink, T data) {}
void add(EventSink<T> sink, T data) => sink.add(data);

@override
void addError(EventSink<T> 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<T> on Stream<T> {
/// Ignore all error events, forward data and done event.
/// Ignore all error events, forward only data and done event.
Stream<T> ignoreErrors() => forwardStream(this, _IgnoreErrorsStreamSink());
}

0 comments on commit 8d6b6f7

Please sign in to comment.