Skip to content

feat: flush events on app pause and make close() awaitable - #110

Merged
Zaimwa9 merged 2 commits into
mainfrom
feat/flush-events-on-pause
Nov 10, 2026
Merged

Zaimwa9 merged 2 commits into
mainfrom
feat/flush-events-on-pause

Conversation

@Zaimwa9

@Zaimwa9 Zaimwa9 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Part of Flagsmith/flagsmith-private#302 (epic Flagsmith/flagsmith-private#362). Covers the background flush and the awaitable close().

Changes

  • Buffered events are flushed when the app becomes hidden, paused or detached. inactive is skipped because it fires on Control Center and incoming calls. If the client is created before the Flutter binding is initialised, the lifecycle hook is skipped with a debug log instead of throwing.
  • close() returns Future<void> and takes an optional timeout (10 s by default). It completes once the final POST finishes or the timeout passes, and never throws. Events tracked after close() are still dropped (fix: drop events tracked after close() #97).
  • README documents when events are flushed, the best-effort limits (iOS suspension, force-quit, web unload) and shutdown.

API change

close() changes from void to Future<void>. Existing client.close(); calls still compile. Subclasses that override close() and fakes that implement FlagsmithClient need to update their signature.

Tests

  • Background flush on hidden/paused/detached; no flush on inactive.
  • await close() waits for the POST; close(timeout:) returns when a slow POST outlasts the timeout.
  • close() removes the lifecycle listener.
  • Creating a client before the Flutter binding exists doesn't throw (own test file, so it doesn't depend on test order).

@Zaimwa9
Zaimwa9 requested a review from a team as a code owner November 9, 2026 14:56
@Zaimwa9
Zaimwa9 requested review from talissoncosta and removed request for a team November 9, 2026 14:56
@coderabbitai

coderabbitai Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Explain Change →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 47 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 147b7047-b096-4d21-84b9-ca99034dd865
Commits

Reviewing files that changed from the base of the PR and between e2a0f46 and 67e9eb0.

Files selected for processing: 3

  • lib/src/flagsmith_client.dart
  • test/fg/flagsmith_experiments_test.dart
  • test/fg/flagsmith_no_binding_test.dart
Walkthrough

The event processor’s stop() method now returns a future that completes after its flush. FlagsmithClient registers a lifecycle observer when events are enabled and flushes buffered events on hidden, paused and detached. Its asynchronous close() waits for the final flush up to a configurable timeout and performs client cleanup. Tests cover lifecycle flushing and close timing. The README documents these behaviours and the updated close() signature.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Severity of issue fixed: Medium

Merge Risk: Low · previous review e2a0f

Shutdown correctly waits for pending uploads within its timeout, but a throwing custom logger can make close fail despite its non-throwing contract. This narrow issue warrants a bounded fix or owner acceptance.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@Zaimwa9
Zaimwa9 removed the request for review from talissoncosta November 9, 2026 14:56
Buffered events are flushed when the app becomes hidden, paused or
detached. close() now returns Future<void> that completes once the final
POST finishes or the timeout (10 s by default) passes. Subclasses that
override close() must update their signature.
@Zaimwa9
Zaimwa9 force-pushed the feat/flush-events-on-pause branch from 30089e7 to e2a0f46 Compare November 9, 2026 14:57

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 39201eab-1fe1-46e8-b913-d27660b344c1
Commits

Reviewing files that changed from the base of the PR and between ad7295e and e2a0f46.

Files selected for processing: 4

  • README.md
  • lib/src/core/events/event_processor.dart
  • lib/src/flagsmith_client.dart
  • test/fg/flagsmith_experiments_test.dart

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Comment thread lib/src/flagsmith_client.dart Resolved
Comment thread lib/src/flagsmith_client.dart Resolved
@Zaimwa9
Zaimwa9 merged commit 4931a95 into main Nov 10, 2026
6 checks passed
@Zaimwa9
Zaimwa9 deleted the feat/flush-events-on-pause branch November 10, 2026 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants