diff options
author | Michael Lehenbauer <mikelehen@gmail.com> | 2018-03-21 14:59:49 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-21 14:59:49 -0700 |
commit | 5f49b2f3f9866e4db13d09857eb3b548239cc62e (patch) | |
tree | f1490f36966b49b73c4fe2e9373b86809db383ec /Firestore/Source/Remote/FSTExponentialBackoff.mm | |
parent | 7854c5164b4440201514b5ab0d90554dd94e9455 (diff) |
Fix for b/74749605: Cancel pending backoff operations when closing streams. (#958)
Diffstat (limited to 'Firestore/Source/Remote/FSTExponentialBackoff.mm')
-rw-r--r-- | Firestore/Source/Remote/FSTExponentialBackoff.mm | 12 |
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; |