Created
February 3, 2016 06:53
-
-
Save onmyway133/3ad9c8c566465667762f to your computer and use it in GitHub Desktop.
Revisions
-
onmyway133 created this gist
Feb 3, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ // 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) } } }