Skip to content

Commit

Permalink
fix(analytics): ensure events auto flush
Browse files Browse the repository at this point in the history
Move timer construction to constructor as the timer is silently broken when instantiated as an instance variable.
  • Loading branch information
fjnoyp committed Nov 14, 2022
1 parent 486bd8d commit f0f5728
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ class AnalyticsClient {
this._eventClient,
this._eventCreator,
this._endpointClient,
);
) {
_autoEventSubmitter = StoppableTimer(
duration: const Duration(seconds: 10),
callback: flushEvents,
);
}

static AnalyticsClient? _instance;

Expand Down Expand Up @@ -113,10 +118,7 @@ class AnalyticsClient {
static const String _sessionStartEventType = '_session.start';
static const String _sessionStopEventType = '_session.stop';

late final StoppableTimer _autoEventSubmitter = StoppableTimer(
duration: const Duration(seconds: 10),
callback: flushEvents,
);
late final StoppableTimer _autoEventSubmitter;

/// Send all cached events to AWS Pinpoint
Future<void> flushEvents() async {
Expand Down

0 comments on commit f0f5728

Please sign in to comment.