diff --git a/packages/state_queue/lib/src/state_queue.dart b/packages/state_queue/lib/src/state_queue.dart index d6abafcc..07aba7ca 100644 --- a/packages/state_queue/lib/src/state_queue.dart +++ b/packages/state_queue/lib/src/state_queue.dart @@ -90,7 +90,7 @@ abstract class StateQueue extends ValueNotifier } }).forEach((nextState) { // don't push any more states after instance is disposed - if (!_taskQueue.isClosed && super.value != nextState) { + if (!isDisposed && super.value != nextState) { _setValue(nextState); } }); @@ -188,8 +188,7 @@ abstract class StateQueue extends ValueNotifier /// of the bloc can not be awaited properly. @protected void run(StateUpdater updater) { - assert(!_taskQueue.isClosed); - + assert(!isDisposed); final entry = _UpdaterEntry( updater, onDone: _pendingOperations.registerPendingOperation('UpdaterEntry'), @@ -205,9 +204,14 @@ abstract class StateQueue extends ValueNotifier super.dispose(); } + @protected + bool get isDisposed => _taskQueue.isClosed; + /// Returns a `Future` which completes once all currently queued tasks have completed @visibleForTesting Future runQueuedTasksToCompletion() async { + assert(!isDisposed); + final completer = Completer(); _taskQueue.sink.add(_CompletionNotifierEntry(completer));