diff options
author | Brad Leege <bleege@gmail.com> | 2015-03-25 21:07:08 -0500 |
---|---|---|
committer | Brad Leege <bleege@gmail.com> | 2015-03-25 21:07:08 -0500 |
commit | b06e8c8dfcdd6d75f07949e1256b4a2f8e6f552e (patch) | |
tree | 0736377b73fc129df48722902cca0f562512eb33 /platform | |
parent | 53090afecbeedfd8838b0fc39a8d0f33d6235eb4 (diff) | |
download | qtlocation-mapboxgl-b06e8c8dfcdd6d75f07949e1256b4a2f8e6f552e.tar.gz |
#1109 - Wrapping event flush method in sync background thread.
Diffstat (limited to 'platform')
-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 { |