Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a serial GCD queue for sending events #318

Merged
merged 1 commit into from
Sep 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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