Skip to content

Instantly share code, notes, and snippets.

@jazzychad
Created July 29, 2014 23:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jazzychad/850a4d9fed017d2a7fa6 to your computer and use it in GitHub Desktop.
Save jazzychad/850a4d9fed017d2a7fa6 to your computer and use it in GitHub Desktop.
mainqueue.c
// in some .h file
extern void runOnMainQueue(dispatch_block_t block);
extern void asyncRunOnMainQueue(dispatch_block_t block);
// in some .m file
void runOnMainQueue(dispatch_block_t block)
{
if (block) {
if ([NSThread isMainThread]) {
block();
} else {
dispatch_sync(dispatch_get_main_queue(), block);
}
}
}
void asyncRunOnMainQueue(dispatch_block_t block)
{
if (block) {
dispatch_async(dispatch_get_main_queue(), block);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment