iOS 控制并发数

  dispatch_semaphore_t semaphore = dispatch_semaphore_create(5);
- (void)request:(void(^)(NSDictionary *))callback {
  dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
    dispatch_semaphore_signal(semaphore);
    callback(@{});
});

}

你可能感兴趣的:(iOS 控制并发数)