Skip to content

Instantly share code, notes, and snippets.

@avesus
Forked from codeswimmer/gcd_timer.m
Last active August 29, 2015 14:14
Show Gist options
  • Save avesus/4472901c77f19b5e26d0 to your computer and use it in GitHub Desktop.
Save avesus/4472901c77f19b5e26d0 to your computer and use it in GitHub Desktop.
dispatch_queue_t gcdTimerQueue;
dispatch_source_t gcdTimer;
gcdTimer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, gcdTimerQueue);
if (gcdTimer) {
uint64_t seconds = 30ull;
uint64_t interval = seconds * NSEC_PER_SEC;
uint64_t leeway = 1ull * NSEC_PER_SEC;
__block typeof(self) _self = self;
dispatch_source_set_timer(gcdTimer, dispatch_walltime(NULL, 0), interval, leeway);
dispatch_source_set_event_handler(gcdTimer, ^{
// stuff to run on a periodic basis
});
dispatch_resume(gcdTimer);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment