aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/Source/Remote/FSTExponentialBackoff.mm
diff options
context:
space:
mode:
Diffstat (limited to 'Firestore/Source/Remote/FSTExponentialBackoff.mm')
-rw-r--r--Firestore/Source/Remote/FSTExponentialBackoff.mm12
1 files changed, 9 insertions, 3 deletions
diff --git a/Firestore/Source/Remote/FSTExponentialBackoff.mm b/Firestore/Source/Remote/FSTExponentialBackoff.mm
index dddf164..20b50a5 100644
--- a/Firestore/Source/Remote/FSTExponentialBackoff.mm
+++ b/Firestore/Source/Remote/FSTExponentialBackoff.mm
@@ -66,9 +66,8 @@ using firebase::firestore::util::SecureRandom;
}
- (void)backoffAndRunBlock:(void (^)(void))block {
- if (self.timerCallback) {
- [self.timerCallback cancel];
- }
+ [self cancel];
+
// First schedule the block using the current base (which may be 0 and should be honored as such).
NSTimeInterval delayWithJitter = _currentBase + [self jitterDelay];
if (_currentBase > 0) {
@@ -89,6 +88,13 @@ using firebase::firestore::util::SecureRandom;
}
}
+- (void)cancel {
+ if (self.timerCallback) {
+ [self.timerCallback cancel];
+ self.timerCallback = nil;
+ }
+}
+
/** Returns a random value in the range [-currentBase/2, currentBase/2] */
- (NSTimeInterval)jitterDelay {
std::uniform_real_distribution<double> dist;