dispose method

Future<void> dispose()
inherited

Closes the stream and cancels the notification subscription.

Closes the stream:

No further events can be added to a closed stream.

The returned future is the same future provided by done. It is completed when the stream listeners is done sending events, This happens either when the done event has been sent, or when the subscriber on a single-subscription stream is canceled.

A broadcast stream controller will send the done event even if listeners are paused, so some broadcast events may not have been received yet when the returned future completes.

If no one listens to a non-broadcast stream, or the listener pauses and never resumes, the done event will not be sent and this future will never complete.

Cancels the notification subscription:

After this call, the subscription no longer receives events.

The stream may need to shut down the source of events and clean up after the subscription is canceled.

Returns a future that is completed once the stream has finished its cleanup.

Typically, cleanup happens when the stream needs to release resources. For example, a stream might need to close an open file (as an asynchronous operation). If the listener wants to delete the file after having canceled the subscription, it must wait for the cleanup future to complete.

If the cleanup throws, which it really shouldn't, the returned future completes with that error.

Implementation

Future<void> dispose() async {
  _logger.finer('dispose KeyStream $this');
  await Future.wait([controller.close(), notificationSubscription.cancel()]);
}