dispose method
Storeの終了処理を行う
NOTE. Task実行中のState不全を避けるため、Disposeは非同期で行われる. 最低限、現在 dispatch に積まれている処理は全て処理され、 その後終了処理が実行される.
Implementation
@mustCallSuper
Future dispose() async {
check(isNotDisposed, 'ReduxStore<$TState> is disposed');
dispatch(_FinalizeAction());
_disposed = true;
try {
while (!_notifier.isClosed) {
await _notifier.wait();
}
} on CancellationException catch (_) {
// Notifierが閉じるのを待つ.
}
assert(_notifier.isClosed, '!Notifier.isClosed');
final latestState = state;
_pluginList
..forEach((element) {
element
..onUnregistered(this)
..dispose();
})
..clear();
await _notifyEvent.close();
await _dispatcher.dispose();
await _subscription.dispose();
await _renderState?.close();
await _state.close();
if (_stateDispose != null) {
// カスタムDisposeに解放処理を行わせる
await _stateDispose!(latestState);
}
}