DoStreamTransformer<T> class

Invokes the given callback at the corresponding point the the stream lifecycle. For example, if you pass in an onDone callback, it will be invoked when the stream finishes emitting items.

This transformer can be used for debugging, logging, etc. by intercepting the stream at different points to run arbitrary actions.

It is possible to hook onto the following parts of the stream lifecycle:

  • onCancel
  • onData
  • onDone
  • onError
  • onListen
  • onPause
  • onResume

In addition, the onEach argument is called at onData, onDone, and onError with a Notification passed in. The Notification argument contains the Kind of event (OnData, OnDone, OnError), and the item or error that was emitted. In the case of onDone, no data is emitted as part of the Notification.

If no callbacks are passed in, a runtime error will be thrown in dev mode in order to "fail fast" and alert the developer that the transformer should be used or safely removed.

Example

new Stream.fromIterable([1])
    .transform(new DoStreamTransformer(
      onData: print,
      onError: (e, s) => print("Oh no!"),
      onDone: () => print("Done")))
    .listen(null); // Prints: 1, "Done"
Inheritance

Constructors

DoStreamTransformer({void onCancel(), void onData(T event), void onDone(), void onEach(Notification<T> notification), Function onError, void onListen(), void onPause(Future resumeSignal), void onResume() })

Properties

transformer StreamTransformer<T, T>
final
hashCode int
The hash code for this object. [...]
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

bind(Stream<T> stream) Stream<T>
Transforms the provided stream. [...]
override
cast<RS, RT>() StreamTransformer<RS, RT>
Provides a StreamTransformer<RS, RT> view of this stream transformer. [...]
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
toString() String
Returns a string representation of this object.
inherited

Operators

operator ==(dynamic other) bool
The equality operator. [...]
inherited