dispose method

Future<void> dispose()

Detaches all listeners and resets initialisation state. The registered service worker itself is left in place (it outlives the page); calling init again re-attaches listeners and re-registers.

Implementation

Future<void> dispose() async {
  await _serviceWorkerMessageStreamSubscription?.cancel();
  await _containerControllerChangeSubscription?.cancel();
  await _serviceWorkerStateChangeSubscription?.cancel();
  await _serviceWorkerErrorSubscription?.cancel();
  await _registrationUpdateFoundSubscription?.cancel();
  await _installingWorkerStateChangeSubscription?.cancel();

  _serviceWorkerMessageStreamSubscription = null;
  _containerControllerChangeSubscription = null;
  _serviceWorkerStateChangeSubscription = null;
  _serviceWorkerErrorSubscription = null;
  _registrationUpdateFoundSubscription = null;
  _installingWorkerStateChangeSubscription = null;

  _serviceWorker = null;
  _registration = null;
  _container = null;
  // Allow init() to run again after disposal.
  _initFuture = null;
}