diff options
author | Sebastian Schmidt <mrschmidt@google.com> | 2017-10-30 18:17:16 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-30 18:17:16 -0700 |
commit | 02ff6bbee95150eacff9563af4dd7a6e1aeaebdd (patch) | |
tree | 8a095ae29bdb6daf273f57913af021c2eae981ab /Firestore/Source/Util | |
parent | 1db9fd83df8d29abe5e7369ad1cbf3eb8545a78a (diff) |
Closing the write and watch stream after 60s of idleness (#388)
Diffstat (limited to 'Firestore/Source/Util')
-rw-r--r-- | Firestore/Source/Util/FSTDispatchQueue.h | 13 | ||||
-rw-r--r-- | Firestore/Source/Util/FSTDispatchQueue.m | 5 |
2 files changed, 18 insertions, 0 deletions
diff --git a/Firestore/Source/Util/FSTDispatchQueue.h b/Firestore/Source/Util/FSTDispatchQueue.h index 256b9c0..fe87887 100644 --- a/Firestore/Source/Util/FSTDispatchQueue.h +++ b/Firestore/Source/Util/FSTDispatchQueue.h @@ -23,6 +23,8 @@ NS_ASSUME_NONNULL_BEGIN /** Creates and returns an FSTDispatchQueue wrapping the specified dispatch_queue_t. */ + (instancetype)queueWith:(dispatch_queue_t)dispatchQueue; +- (instancetype)initWithQueue:(dispatch_queue_t)queue NS_DESIGNATED_INITIALIZER; + - (instancetype)init __attribute__((unavailable("Use static constructor method."))); /** @@ -50,6 +52,17 @@ NS_ASSUME_NONNULL_BEGIN */ - (void)dispatchAsyncAllowingSameQueue:(void (^)(void))block; +/** + * Schedules a callback after the specified delay. + * + * Unlike dispatchAsync: this method does not require you to dispatch to a different queue than + * the current one (thus it is equivalent to a raw dispatch_after()). + * + * @param block The block to run. + * @param delay The delay (in seconds) after which to run the block. + */ +- (void)dispatchAfterDelay:(NSTimeInterval)delay block:(void (^)(void))block; + /** The underlying wrapped dispatch_queue_t */ @property(nonatomic, strong, readonly) dispatch_queue_t queue; diff --git a/Firestore/Source/Util/FSTDispatchQueue.m b/Firestore/Source/Util/FSTDispatchQueue.m index 9613102..8c953fe 100644 --- a/Firestore/Source/Util/FSTDispatchQueue.m +++ b/Firestore/Source/Util/FSTDispatchQueue.m @@ -56,6 +56,11 @@ NS_ASSUME_NONNULL_BEGIN dispatch_async(self.queue, block); } +- (void)dispatchAfterDelay:(NSTimeInterval)delay block:(void (^)(void))block { + dispatch_time_t delayNs = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC)); + dispatch_after(delayNs, self.queue, block); +} + #pragma mark - Private Methods - (NSString *)currentQueueLabel { |