Skip to content

Instantly share code, notes, and snippets.

@jdriscoll
Created September 18, 2012 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdriscoll/3743534 to your computer and use it in GitHub Desktop.
Save jdriscoll/3743534 to your computer and use it in GitHub Desktop.
Repeating work on background thread with GCD and blocks
- (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