Skip to content

Commit

Permalink
Use a serial GCD queue for sending events
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadim Yeshkunov committed Sep 29, 2021
1 parent d505e08 commit d8e1cc3
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions Sources/MapboxMobileEvents/MMEEventsManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ @interface MMEEventsManager () <MMELocationManagerDelegate>
@property (nonatomic, getter=isPaused) BOOL paused;
@property (nonatomic) id<MMEUIApplicationWrapper> application;
@property (nonatomic) UIBackgroundTaskIdentifier backgroundTaskIdentifier;

@property (nonatomic) dispatch_queue_t eventsDispatchQueue;
@end

// MARK: -
Expand Down Expand Up @@ -79,6 +79,7 @@ - (instancetype)initShared {
_uniqueIdentifer = [[MMEUniqueIdentifier alloc] initWithTimeInterval:NSUserDefaults.mme_configuration.mme_identifierRotationInterval];
_application = [[MMEUIApplicationWrapper alloc] init];
_dispatchManager = [[MMEDispatchManager alloc] init];
_eventsDispatchQueue = dispatch_queue_create("com.mapbox.mme.events", DISPATCH_QUEUE_SERIAL);
}
return self;
}
Expand Down Expand Up @@ -355,8 +356,7 @@ - (void)sendTurnstileEvent {

MMELOG(MMELogInfo, MMEDebugEventTypeTurnstile, ([NSString stringWithFormat:@"Sending turnstile event: %@, instance: %@", turnstileEvent , self.uniqueIdentifer.rollingInstanceIdentifer ?: @"nil"]));

dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
dispatch_async(_eventsDispatchQueue, ^{
__weak __typeof__(self) weakSelf = self;
[self.apiClient postEvent:turnstileEvent completionHandler:^(NSError * _Nullable error) {
@try {
Expand All @@ -383,8 +383,7 @@ - (void)sendTurnstileEvent {
}

- (void)sendPendingMetricsEvent {
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
dispatch_async(_eventsDispatchQueue, ^{
MMEEvent *pendingMetricsEvent = [MMEMetricsManager.sharedManager loadPendingTelemetryMetricsEvent];

if (pendingMetricsEvent) {
Expand All @@ -400,8 +399,7 @@ - (void)sendPendingMetricsEvent {
}

- (void)sendTelemetryMetricsEvent {
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
dispatch_async(_eventsDispatchQueue, ^{
@try {
MMEEvent *telemetryMetricsEvent = [MMEMetricsManager.sharedManager generateTelemetryMetricsEvent];

Expand Down

0 comments on commit d8e1cc3

Please sign in to comment.