dispose method

  1. @nonVirtual
  2. @override
Future<void> dispose()
override

Clean up resources - Closes the streams.

This method should be called when a RxStorage is no longer needed. But in a real application, this method is rarely called.

Once dispose is called:

  • All streams will not emit changed value when value changed.
  • All pending writing tasks will be discarded.

Implementation

@nonVirtual
@override
Future<void> dispose() {
  assert(_debugAssertNotDisposed());

  Future<void> dispose() =>
      Future.wait(_writeQueueResources.values.map((q) => q.dispose()))
          .then((_) => _writeQueueResources.clear())
          .then((_) => _bag.dispose());
  final future = _disposeMemo.runOnce(dispose);
  return _onDispose?.let((onDispose) => future.then((_) => onDispose())) ??
      future;
}