Last active
November 16, 2016 13:25
-
-
Save proactive-solutions/62d31ff13aec246f2d6ace554cc87417 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface PingThread : NSThread | |
@property (nonatomic, assign) BOOL pingTaskIsRunning; | |
@property (nonatomic, strong) dispatch_semaphore_t semaphore; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation PingThread | |
- (void)main { | |
self.semaphore = dispatch_semaphore_create(0); | |
self.pingTaskIsRunning = NO; | |
while (NO == self.isCancelled) { | |
self.pingTaskIsRunning = YES; | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
self.pingTaskIsRunning = false; | |
dispatch_semaphore_signal(self.semaphore); | |
}); | |
[NSThread sleepForTimeInterval:0.4]; | |
if (YES == self.pingTaskIsRunning) { | |
NSLog(@"handle the operation here"); | |
} | |
dispatch_semaphore_wait(self.semaphore, DISPATCH_TIME_FOREVER); | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment