Created
July 8, 2014 07:54
-
-
Save yasirmturk/76cb724657b0105b0a38 to your computer and use it in GitHub Desktop.
Avoid multiple Executions of a method at any given time
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
dispatch_semaphore_t semaphore = dispatch_semaphore_create(1); | |
dispatch_queue_t renderQueue = dispatch_queue_create("com.throttling.queue", NULL); | |
- (void) onlyExecuteOnceAtATime { | |
if (dispatch_semaphore_wait(semaphore, DISPATCH_TIME_NOW) == 0) { | |
dispatch_async(renderQueue, ^{ | |
// execution code goes here | |
dispatch_semaphore_signal(semaphore); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment