onClose method

  1. @override
GenericStream<T> onClose(
  1. void closeHandler()
)
override

Returns an equivalent stream with an additional close handler.

Close handlers are run when the close method is called on the stream, and are executed in the order they were added. All close handlers are run, even if earlier close handlers throw exceptions.

This is an intermediate operation.

Example

final stream = DartStream.of([1, 2, 3, 4, 5])
    .onClose(() => print('First handler'))
    .onClose(() => print('Second handler'));

stream.close(); // Prints both messages

Implementation

@override
GenericStream<T> onClose(void Function() closeHandler) {
  return StandardGenericStream(_source, _parallel, [..._closeHandlers, closeHandler]);
}