Skip to content

Prevent request cubits from emitting after close#58

Merged
dawid-niedzwiecki merged 4 commits into
mainfrom
fix/request-cubit-close-race
May 8, 2026
Merged

Prevent request cubits from emitting after close#58
dawid-niedzwiecki merged 4 commits into
mainfrom
fix/request-cubit-close-race

Conversation

@dawid-niedzwiecki

@dawid-niedzwiecki dawid-niedzwiecki commented May 7, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Prevent BaseRequestCubit from emitting after it has been closed by guarding emits across async gaps.
  • Cancel the in-flight request operation when the cubit closes.
  • Add regression coverage for closing during a pending request and during async result handling.

@dawid-niedzwiecki dawid-niedzwiecki requested review from KamilSztandur and piotruela and removed request for KamilSztandur May 7, 2026 00:17
@dawid-niedzwiecki dawid-niedzwiecki self-assigned this May 7, 2026
@dawid-niedzwiecki dawid-niedzwiecki added the bug Something isn't working label May 7, 2026
Comment thread packages/leancode_cubit_utils/lib/src/request/request_cubit.dart
Comment thread packages/leancode_cubit_utils/test/request_cubit_test.dart Outdated
@dawid-niedzwiecki dawid-niedzwiecki merged commit d1b3ff2 into main May 8, 2026
1 check passed
'Processing error failed. Exception: $e. Stack trace: $s',
);
emit(RequestErrorState<TOut, TError>(exception: e, stackTrace: s));
if (isClosed) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_emitIfOpen already guards the isClosed


CancelableOperation<TRes>? _operation;

void _emitIfOpen(RequestState<TOut, TError> state) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_safeEmit maybe?

@dawid-niedzwiecki dawid-niedzwiecki deleted the fix/request-cubit-close-race branch May 18, 2026 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants