Skip to content

Commit

Permalink
Rename and add block to parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Anna Kocheshkova committed Aug 17, 2020
1 parent 08ec470 commit 54b550f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
Expand Up @@ -215,7 +215,8 @@ - (void)setEnabled:(BOOL)isEnabled andDeleteDataOnDisabled:(BOOL)deleteData {
- (void)applicationWillTerminate:(__unused UIApplication *)application {

// Block logs queue so that it isn't killed before app termination.
[MSDispatcherUtil dispatchAsyncWithTimeout:1 onQueue:self.logsDispatchQueue];
[MSDispatcherUtil dispatchSyncWithTimeout:1 onQueue:self.logsDispatchQueue withBlock: ^{
}];
}
#endif

Expand Down
3 changes: 2 additions & 1 deletion AppCenter/AppCenter/Internals/Util/MSDispatcherUtil.h
Expand Up @@ -18,7 +18,8 @@
* Adds a dispatch_async block to the provided queue and waits for its execution.
* @param timeout timeout for waiting in seconds.
* @param dispatchQueue the queue to perform block on.
* @param block the block to be executed.
*/
+ (void)dispatchAsyncWithTimeout:(int)timeout onQueue:(dispatch_queue_t)dispatchQueue;
+ (void)dispatchSyncWithTimeout:(int)timeout onQueue:(dispatch_queue_t)dispatchQueue withBlock:(dispatch_block_t)block;

@end
3 changes: 2 additions & 1 deletion AppCenter/AppCenter/Internals/Util/MSDispatcherUtil.m
Expand Up @@ -23,9 +23,10 @@ + (void)runBlock:(void (^)(void))block {
block();
}

+ (void)dispatchAsyncWithTimeout:(int)timeout onQueue:(dispatch_queue_t)dispatchQueue {
+ (void)dispatchSyncWithTimeout:(int)timeout onQueue:(dispatch_queue_t)dispatchQueue withBlock:(dispatch_block_t)block {
dispatch_semaphore_t delayedProcessingSemaphore = dispatch_semaphore_create(0);
dispatch_async(dispatchQueue, ^{
block();
dispatch_semaphore_signal(delayedProcessingSemaphore);
});
dispatch_semaphore_wait(delayedProcessingSemaphore, dispatch_time(DISPATCH_TIME_NOW, timeout * NSEC_PER_SEC));
Expand Down

0 comments on commit 54b550f

Please sign in to comment.