From ea3979b19e08d5893347e648bbdc28bbb9bfe010 Mon Sep 17 00:00:00 2001 From: Brad Leege Date: Fri, 8 May 2015 10:13:05 -0500 Subject: [PATCH 1/3] #1474 - Refactoring timer to be started when first event is added to queue. Debug logic and content also included --- platform/ios/MGLMapboxEvents.m | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/platform/ios/MGLMapboxEvents.m b/platform/ios/MGLMapboxEvents.m index 4450fa87f..b5a219546 100644 --- a/platform/ios/MGLMapboxEvents.m +++ b/platform/ios/MGLMapboxEvents.m @@ -163,7 +163,7 @@ NSString *const MGLEventGestureRotateStart = @"Rotation"; // Events Control _eventQueue = [[NSMutableArray alloc] init]; _flushAt = 20; - _flushAfter = 60; + _flushAfter = 15; _token = nil; _instanceID = [[NSUUID UUID] UUIDString]; @@ -382,16 +382,20 @@ NSString *const MGLEventGestureRotateStart = @"Rotation"; // Has Flush Limit Been Reached? if (_eventQueue.count >= strongSelf.flushAt) { [strongSelf flush]; + } else if (_eventQueue.count == 1) { + // If this is first new event on queue start timer, + NSLog(@"event queue is 1, start timer."); + [strongSelf startTimer]; + } else { + NSLog(@"event queue is != 1, don't adjust timer."); } - - // Reset Timer (Initial Starting of Timer after first event is pushed) - [strongSelf startTimer]; }); } // Can be called from any thread. // + (void) flush { + NSLog(@"+flush called (likely timer)"); [[MGLMapboxEvents sharedManager] flush]; } From 11886a9004e03a5fb360ae7ad766f85754f2a253 Mon Sep 17 00:00:00 2001 From: Brad Leege Date: Fri, 8 May 2015 10:21:00 -0500 Subject: [PATCH 2/3] #1474 - Adding timer cleanup logic to -flush so that it doesn't loop indefinitely --- platform/ios/MGLMapboxEvents.m | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/platform/ios/MGLMapboxEvents.m b/platform/ios/MGLMapboxEvents.m index b5a219546..c4d6d425c 100644 --- a/platform/ios/MGLMapboxEvents.m +++ b/platform/ios/MGLMapboxEvents.m @@ -429,6 +429,13 @@ NSString *const MGLEventGestureRotateStart = @"Rotation"; // Send Array of Events to Server [strongSelf postEvents:events]; + + // Cancel Any Timer That May Running + if (strongSelf.timer) { + NSLog(@"timer still exists after flush, need to clean it up."); + [strongSelf.timer invalidate]; + strongSelf.timer = nil; + } }); } From 9f0e9fe847eb0713cc0907c72d174e1d439ba5fc Mon Sep 17 00:00:00 2001 From: Brad Leege Date: Fri, 8 May 2015 10:23:14 -0500 Subject: [PATCH 3/3] #1474 - Setting flushAfter back to 60 seconds. Removing debug log statements --- platform/ios/MGLMapboxEvents.m | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/platform/ios/MGLMapboxEvents.m b/platform/ios/MGLMapboxEvents.m index c4d6d425c..93891217c 100644 --- a/platform/ios/MGLMapboxEvents.m +++ b/platform/ios/MGLMapboxEvents.m @@ -163,7 +163,7 @@ NSString *const MGLEventGestureRotateStart = @"Rotation"; // Events Control _eventQueue = [[NSMutableArray alloc] init]; _flushAt = 20; - _flushAfter = 15; + _flushAfter = 60; _token = nil; _instanceID = [[NSUUID UUID] UUIDString]; @@ -384,10 +384,7 @@ NSString *const MGLEventGestureRotateStart = @"Rotation"; [strongSelf flush]; } else if (_eventQueue.count == 1) { // If this is first new event on queue start timer, - NSLog(@"event queue is 1, start timer."); [strongSelf startTimer]; - } else { - NSLog(@"event queue is != 1, don't adjust timer."); } }); } @@ -395,7 +392,6 @@ NSString *const MGLEventGestureRotateStart = @"Rotation"; // Can be called from any thread. // + (void) flush { - NSLog(@"+flush called (likely timer)"); [[MGLMapboxEvents sharedManager] flush]; } @@ -432,7 +428,6 @@ NSString *const MGLEventGestureRotateStart = @"Rotation"; // Cancel Any Timer That May Running if (strongSelf.timer) { - NSLog(@"timer still exists after flush, need to clean it up."); [strongSelf.timer invalidate]; strongSelf.timer = nil; }