Can I limit concurrent requests using GCD?

grand-central-dispatch, objective-c

Solution

Something like this:

...
//only make one of these obviously :) remaking it each time you dispatch_async wouldn't limit anything
dispatch_semaphore_t concurrencyLimitingSemaphore = dispatch_semaphore_create(limit);
...
//do this part once per task, for example in a loop
dispatch_semaphore_wait(concurrencyLimitingSemaphore, DISPATCH_TIME_FOREVER);
dispatch_async(someConcurrentQueue, ^{
    /* work goes here */
    dispatch_semaphore_signal(concurrencyLimitingSemaphore);
}

Problem

I'm acquiring data from a database asynchronously. Is there any way I can limit the concurrent requests to a number, but still execute the rest? I saw a post using NSOperation and NSOperationQueue but this is too complicated for me. Is there any other ways to do it? Can GCD achieve it?

Original source