//创建一个全局队列
dispatch_queue_t queue = dispatch_get_global_queue(0, 0);
//创建一个信号量(值为0)
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
dispatch_async(queue, ^{
NSLog(@"执行 === 1");
[GroupRecordAPI getDadaWith:1 andCondition:nil success:^(id obj) {
NSLog(@"执行 === 2-1");
dispatch_semaphore_signal(semaphore);
} failure:^(id obj) {
NSLog(@"执行 === 2-2");
dispatch_semaphore_signal(semaphore);
}];
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
NSLog(@"执行 === 3");
});
打印结果
2018-05-08 14:25:45.734599+0800 uAcademic[392:104334] 执行 === 1
2018-05-08 14:25:46.809465+0800 uAcademic[392:104283] 执行 === 2-1
2018-05-08 14:25:46.809808+0800 uAcademic[392:104334] 执行 === 3
网友评论