Created
September 18, 2012 14:48
-
-
Save jdriscoll/3743534 to your computer and use it in GitHub Desktop.
Repeating work on background thread with GCD and blocks
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
- (void)doStuff | |
// Do stuff on main thread | |
dispatch_async(self.queue, ^{ | |
// Do stuff on background thread | |
// self.queue is a serial queue stored as a property on this object | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
// Do stuff on main thread | |
}); | |
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, self.delay * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ | |
// Call doStuff again on the main thread after delay | |
[self doStuff]; | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment