Created
May 21, 2014 17:27
-
-
Save jmbeck/a837bfa89deea6aa3b58 to your computer and use it in GitHub Desktop.
GCD Background Thread Helpers
This file contains 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 perform_block_after_delay(CGFloat seconds, dispatch_block_t block) { | |
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, seconds * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ | |
block(); | |
}); | |
} | |
void perform_block_on_main(dispatch_block_t block) { | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
block(); | |
}); | |
} | |
void perform_block_in_bg_after_delay(CGFloat seconds, dispatch_block_t block) { | |
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, seconds * NSEC_PER_SEC), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ | |
block(); | |
}); | |
} | |
void perform_block_in_bg(dispatch_block_t block) { | |
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0 * NSEC_PER_SEC), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ | |
block(); | |
}); | |
} | |
void perform_block_in_bg_high(dispatch_block_t block) { | |
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0 * NSEC_PER_SEC), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ | |
block(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment