diff options
Diffstat (limited to 'platform/ios/MGLMapboxEvents.m')
-rw-r--r-- | platform/ios/MGLMapboxEvents.m | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/platform/ios/MGLMapboxEvents.m b/platform/ios/MGLMapboxEvents.m index 789ac4d108..838fd11d36 100644 --- a/platform/ios/MGLMapboxEvents.m +++ b/platform/ios/MGLMapboxEvents.m @@ -180,24 +180,26 @@ NSNumber *scale; return; } - int upper = (int)_flushAt; - if (_flushAt > [_queue count]) { - if ([_queue count] == 0) { - return; - } - upper = (int)[_queue count]; - } + dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ - // Create Array of Events to push to the Server - NSRange theRange = NSMakeRange(0, upper); - NSArray *events = [_queue subarrayWithRange:theRange]; + int upper = (int)_flushAt; + if (_flushAt > [_queue count]) { + if ([_queue count] == 0) { + return; + } + upper = (int)[_queue count]; + } - // Update Queue to remove events sent to server - [_queue removeObjectsInRange:theRange]; + // Create Array of Events to push to the Server + NSRange theRange = NSMakeRange(0, upper); + NSArray *events = [_queue subarrayWithRange:theRange]; - // Send Array of Events to Server - [self postEvents:events]; + // Update Queue to remove events sent to server + [_queue removeObjectsInRange:theRange]; + // Send Array of Events to Server + [self postEvents:events]; + }); } - (void) postEvents:(NSArray *)events { |