onWillDispose method

  1. @override
Future<Null> onWillDispose()

Callback to allow arbitrary cleanup as soon as disposal is requested (i.e. dispose is called) but prior to disposal actually starting.

Disposal will not start before the Future returned from this method completes.

Implementation

@override
Future<Null> onWillDispose() async {
  // If the client is already closed, there is nothing to do.
  if (_jsClient.readyState == 3 /* closed */) {
    return;
  }

  // Close this client. If already closing, this will be a no-op.
  close();

  // Wait for the event to be emitted on the `onClose` stream. This ensures
  // that the underlying StreamController is not disposed too early.
  await onClose.first;
}