Created
February 3, 2016 06:53
-
-
Save onmyway133/3ad9c8c566465667762f to your computer and use it in GitHub Desktop.
PingThread.swift
This file contains hidden or 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
// from https://dl.dropboxusercontent.com/u/3820193/VbierClientUnderTheHood.pdf | |
class PingThread : NSThread { | |
var pingTaskIsRunning = false | |
var semaphore = dispatch_semaphore_create(0) | |
override func main() { | |
while !self.cancelled { | |
pingTaskIsRunning = true | |
dispatch_async(dispatch_get_main_queue()) { | |
self.pingTaskIsRunning = false | |
dispatch_semaphore_signal(self.semaphore) | |
} | |
NSThread.sleepForTimeInterval(0.4) | |
if pingTaskIsRunning { | |
// warning here | |
} | |
dispatch_semaphore_wait(semaphore, | |
DISPATCH_TIME_FOREVER) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there a swift4 version of it